#include<bits/stdc++.h>
using namespace std;
int depth=4;
int k=2;
int ans=0;
bool value[1<<20]={false};
void dfs(int x){
if(x>=(1<<(depth-1))){
ans=x;
return;
}
if(value[x]==false){
value[x]=true;
dfs(2*x);
}else{
value[x]=false;
dfs(2*x+1);
}
}
int main(){
int t;
cin >> t;
for(int i=1;i<=t;i++){
cin >> depth >> k;
for(int i=1;i<=k;i++){
dfs(1);
}
cout << ans << endl;
ans=0;
}
return 0;
}