#include <bits/stdc++.h>
using namespace std;
int d, n, t;
int main() {
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
scanf("%d", &t);
while (t--) {
scanf("%d%d", &d, &n);
int ans = 1;
for (int i = 1; i < d; i++) {
if (n & 1) {
ans <<= 1;
n = (n + 1) >> 1;
} else {
ans = ans << 1 | 1;
n >>= 1;
}
}
printf("%d\n", ans);
}
return 0;
}