#include<bits/stdc++.h>
using namespace std;

#define ll long long

ll M = 998244353;

ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }

const int N = 5e5 + 5;
ll fact[N], inv[N];
 
void pre(int n){fact[0] = inv[0] = 1;for(ll i=1;i<=n;i++){fact[i] = (fact[i-1]*i)%M;inv[i] = powerm(fact[i],M-2);}}
 
ll C(ll n,ll r){ll ans = ((fact[n]*inv[r])%M + M)%M;ans = ((ans*inv[n-r])%M + M)%M;return ans;}

int main(){
    ll t=1;
    cin>>t;
    //cout<<t<<endl;
    while(t--){
        int n,k;
        cin>>n>>k;
        k--;
        if(n%2==0){
            int net=(k)%n;
            cout<<1+net<<endl;
        }
        else{
            int skip=k/((n-1)/2);
            int net=(k+skip)%n;
            cout<<1+net<<endl;
            
        }
    }
}