import math
k = int(input())
def get_pos(n, idx):
if n == 1:
ans = [(0, 0), (1, 0), (1, 1), (0, 1)]
return ans[idx]
block_size = 1 << (2*n - 2)
block_idx = idx // block_size
# 子块中的相对下标
sub_idx = idx - block_size * block_idx
pos = get_pos(n-1, sub_idx)
if block_idx == 0:
new_pos = (pos[1], pos[0])
return (0 + new_pos[0], 0 + new_pos[1])
elif block_idx == 1:
new_pos = (pos[0], pos[1])
return ((1<<(n-1)) + new_pos[0], new_pos[1])
elif block_idx == 2:
new_pos = (pos[0], pos[1])
return ((1<<(n-1)) + new_pos[0], (1<<(n-1)) + new_pos[1])
else:
new_pos = ((1<<(n-1)) - 1 - pos[1], (1<<(n-1)) -1 - pos[0])
return (new_pos[0], (1<<(n-1)) + new_pos[1])
for _ in range(k):
n, a, b = map(int, input().split())
pos1, pos2 = get_pos(n, a-1), get_pos(n, b-1)
ans = math.sqrt((pos1[0] - pos2[0])**2 + (pos1[1] - pos2[1])**2)
print(int(ans*10+0.5))