#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k,ans;
        cin >> n >> k;
        if(n%2==0) {
            if(k%n==0) ans=n;
            else ans=k%n;
        }
        else {
            int rec=(1+n)/2-1;
            int cnt=(k-1)/rec;
            //cout << rec << " " << cnt << endl;
            ans=((k%n)+cnt)%n;
            if(ans==0) ans=n;
        }
        cout << ans << endl;
    }
}
