#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,x;
        cin>>n>>x;
        if(n%2==0) {
            ll temp = x % n;
            if(temp==0)
                temp=n;
            printf("%lld\n", temp);
        } else
        {
            ll temp=0;
            if(x>n/2)
            {
                temp+=n/2+2;
                x=x-n/2-1;
                if(x>0)
                {
                    ll l1=x/(n/2);
                    ll l2=x%(n/2);
                    temp+=l1*(n/2+1);
                    temp+=l2;
                }
                temp=temp%n;
                if(temp==0)
                    temp=n;
                printf("%lld\n",temp);
            } else
            {
                printf("%lld\n",x);
            }
        }
    }
}