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

const int N=10010,M=3000,inf=0x3f3f3f3f;
int n,p,k;
int id[N],dist[N],q[N];
bool st[N]; 
  
int main()
{
	int t;cin>>t;
	while(t--)
	{
		cin>>n>>k;
		memset(q,0,sizeof q);
		long long i=1;
		if(n%2==0) 
		{
			k-=1;
			i+=k%n;
		}
	    else 
		{
			int x=n/2;
			k-=1;
			int m=k/x;
			i=i+(m+k)%n; 
		}
		cout<<i<<endl;
	}
	 
	return 0;
}