#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
long long n, s, t;
cin >> n >> s >> t;
if (s == t) {
cout << 0 << endl;
continue;
}
if (t == (1 << n) - 1)
{
cout << (s ^ t) << endl;
continue;
}
long long ans = 0;
long long x = ((1 << n) - 1) ^ s;
ans = s ^ x;
if (x != t)
ans += x ^ t;
cout << ans << endl;
}
return 0;
}