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

#define int long long
#define mod 1000000007
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define pb push_back
#define endl '\n'

void tests(){
	int n,k;
	cin>>n>>k;

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