#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
	// your code goes here
	int t, n, a, b, at, bt, ac, bc, total, r;
	scanf("%d", &t);
	while(t--) {
		scanf("%d %d %d", &n, &a, &b);
		at=0; bt=0; ac=0; bc=0; r=0;
		while(a) { if(a%2) ac++; at=at*10+a%2; a=a/2; }
		while(b) { if(b%2) bc++; bt=bt*10+b%2; b=b/2; }
		total=ac+bc; 
		if(total<n);
		else total=2*n-(ac+bc);
		while(total--) { r=r+pow(2, (n-1)); n--; }
		printf("%d\n", r);
	}
	return 0;
}