#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll line,n,k,i,j,ans;
    cin>>line;
    while(line--)
    {
        cin>>n>>k;
        if(n%2==0)
        {
            ans=k%n;
            if(ans==0) ans=n;
        }
        else
        {
            ans=k%n;
            if(ans==0) ans=n;
            ll a=(n+1)/2LL;
           // cout<<"bal: "<<a<<' '<<k<<endl;
            if(a<=k)
            {
                ll term=(k-a)/(n/2LL);
                term++;
                ans=(ans+term)%n;
                if(ans==0) ans=n;
            }
        }
        cout<<ans<<endl;
    }

    /*ll n,k,i,j;
    cin>>n>>k;
    ll a=n,b=1,cnt=0;
    for(i=2; i<=k; i++)
    {
        a--,b++;
        if(a==0) a=n;
        if(b==n+1) b=1;
        if(a==b)
        {
            cout<<"ok: "<<i<<endl;
            b++;
            if(b==n+1) b=1;
            cnt++;
        }
    }
    cout<<"ans: "<<b<<' '<<cnt<<endl;*/

}

