#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int l,d,i,ans;
bool a[21] = {false};
void dfs(int x){
if(x >= (1 << (d - 1))){
ans = x;
return;
}
if(a[x] == false) {a[x] = true;dfs(x * 2);}
else {a[x] = false;dfs(x * 2 + 1);}
}
int main()
{
cin >> l;
while(l--){
memset(a,0,sizeof(a));
cin >> d >> i;
for(int j = 1;j <= i;j++) dfs(1);
cout << ans << endl;
}
return 0;
}