#include<bits/stdc++.h>
using namespace std;
int n,k,t;
int main()
{
    std::ios::sync_with_stdio(0);
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        if(n%2==0)
        {
            if(k%n==0)
            {
                cout<<n<<endl;
            }
            else
            {
                cout<<k%n<<endl;
            }
        }
        else
        {
            int meet=(k-1)/(n>>1);
            int step=k-1;
            int ans=1+(step+meet)%n;
            cout<<ans<<endl;
        }
    }
    return 0;
}
