#include <bits/stdc++.h>
using namespace std;
const int N =9999999;
const double pi=acos(-1);
 
int n,t,ans,a[N],k,s1,s2;
int main(){
	cin>>t;
	while(t--){
		cin>>n>>k;
		if(n%2==1)cout<<((k-1)+((k-1))/(n/2))%n+1<<endl;
		else cout<<(k-1)%n+1<<endl;
	}
	return 0;
}