#include<bits/stdc++.h>#define int long long#define pii pair<int, int>#define pb push_back#define mk make_pair#define F first#define S secondusingnamespacestd;intifloor(inta,intb){if(b<0)a*=-1,b*=-1;if(a<0)return(a-b+1)/b;elsereturna/b;}inticeil(inta,intb){if(b<0)a*=-1,b*=-1;if(a>0)return(a+b-1)/b;elsereturna/b;}intF(intn,intk){if(n==1)return1;if(k<=iceil(n,2)){if(n%2==0)return2*k;elsereturn(2*k)%n;}intidx;if(n%2==0)idx=F(n/2,k-(n/2));elseidx=F(ifloor(n,2),k-iceil(n,2));intnow_index;if(n%2==0)now_index=2*idx-1;elsenow_index=2*idx+1;returnnow_index;}voidsolve(){intn,k;cin>>n>>k;cout<<F(n,k)<<"\n";}signedmain(){// ios::sync_with_stdio(0);// cin.tie(0);intt=1;cin>>t;while(t--){solve();}}