#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
typedef long long LL;
pair<LL, LL> trans(LL z,int n) {
LL x, y;
if (n == 1) {
if (z == 1) x = 1, y = 1;
if (z == 2) x = 1, y = 2;
if (z == 3) x = 2, y = 2;
if (z == 4) x = 2, y = 1;
return pair<LL, LL>(x, y);
}
LL len = 1LL << (n - 1);
LL lenn = 1LL << 2 * n - 2;
int k = z - 1 >> 2 * n - 2;
auto p = trans((z - 1) % lenn + 1, n - 1);
switch (k){
case 0:
x = p.second;
y = p.first;
break;
case 1:
x = p.first;
y = p.second + len;
break;
case 2:
x = p.first + len;
y = p.second +len;
break;
case 3:
x = 2*len - p.second + 1;
y = len - p.first + 1;
break;
default:
break;
}
return pair<LL, LL>(x, y);
}
int main() {
int t;
cin >> t;
while (t--) {
LL n, a, b;
cin >> n >> a >> b;
auto A = trans(a, n);
auto B = trans(b, n);
LL dx = A.first - B.first;
LL dy = A.second - B.second;
double k = sqrt((dx * dx + dy * dy)) * 10;
printf("%.0lf\n", k);
}
return 0;
}