program kahf;
var j,k,n,m,d,t,i:longint;
begin
assign(input,'fballs.in');reset(input);
assign(output,'fballs.out');rewrite(output);
readln(n);
for j:=1 to n do
begin
readln(d,t);
k:=1;
for i:=1 to d-1 do
begin
if(t mod 2<>0)then
begin
k:=k*2;
t:=(t+1)div 2;
end
else
begin
k:=k*2+1;
t:=t div 2;
end;
end;
writeln(k);
end;
readln(m);
close(input);
close(output);
end.