#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PB push_back
#define MP make_pair

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; cin>>t;
    while(t--){
    	ll n,k; cin>>n>>k;
        if(n%2==0){
            if(k%n==0){
                cout<<n<<endl;
            }else{
                cout<<k%n<<endl;
            }
        }else{
            int mid=n/2;
            if(k%mid==0){
                k+=k/mid-1;
            }else{
                k+=k/mid;
            }
            if(k%n==0){
                cout<<n<<endl;
            }else{
                cout<<k%n<<endl;
            }
        }
    }
	return 0;
}