#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        if((n&1)==0)
        {
            if((k%n)==0)
            cout<<n<<endl;
            else
            cout<<k%n<<endl;
        }
        else
        {
            int pos=1;
            int ti;
            if(k<=(n/2))
            cout<<k<<endl;
            else
            {
            	k--;
                ti=k/(n/2);
                ti=ti*(n/2+1);
                ti++;
                ti=ti+(k%(n/2));
                ti=ti%n;
                if(ti==0)
                cout<<n<<endl;
                else
                cout<<ti<<endl;
            }
        }
    }
    return 0;
}