        #include <iostream>
        #include <string>
        #include<bits/stdc++.h>
        #include<algorithm>
        using namespace std;
        int main()
        {
            int t;
            cin>>t;
            while(t--)
            {
                long long n,k;
                cin>>n>>k;
                long long a=n,b=1;
                if(n%2==0)
                {
                    k--;
                    k=k%n;
                    cout<<b+k<<endl;
                }
                else
                {
                    k--;
                    long long t=n/2;
                    long long y=k/t;
                    long long j=k+y+1;
                    long long ans=j%n;
                    if(!ans)ans=n;
                    cout<<ans<<endl;
                }
            }
        }