#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
const int inf=0x3f3f3f3f;
const int maxn=1e3+5;
const int N=6e6+5;
const LL mod=1e9+7;
const double pi=acos(-1);
int main()
{
    LL n,k,t,res,now;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld%lld",&n,&k);
        if(n%2==0)
        {
            if(k%n) res=k%n;
            else res=n;
            printf("%lld\n",res);
        }
        else
        {
            now=n/2;
            int tt=(k-1)/now;
            res=(k+tt)%n;
            if(res==0) res=n;
            printf("%lld\n",res);
        }
    }
    return 0;
}