#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);


signed main(void)
{
    fastio;
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        if(n&1){
            int temp = n/2 + 1;
            int t1 = n/2;
            if(k<temp){
                cout<<k<<endl;
            }
            else{
                int cntr = (k - temp)/(t1);
                int ans = (k + cntr)%n;
                cout<<ans+1<<endl;
            }
        }
        else{
            int temp = (k-1)%n;
            cout<<temp+1<<endl;
        }
    }
}
