#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
int main() 
{
	ll t;
	cin>>t;
	while(t--){
		ll n,k;
		cin>>n>>k;
		ll ans;
		if(n%2==0)
		{
			if(k%n==0)
			ans=n;
			else
			ans=k%n;
		}
		else {
			ll x1=k%n;
			if(x1==0)
			x1=n;
			ll x2=(k/n);
			if(k%n!=0)
			x2++;
			ll x3=x2%(n/2);
			if(x3==0)
			x3=n/2;
			ll x4=(x3-1)*n+x1;
			ll x5=x4/(n/2);
			if(x4%(n/2)==0)
			x5--;
			ans=(x1+x5)%n;
			if(ans==0)
			ans=n;
		}
		cout<<ans<<endl;
	}
	return 0;
} 
  
