#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

inline void slv(){
	int n, k;
	cin >> n >> k;
	if(n%2==0){
		k %= n;
		k = (k==0?n:k);
		cout << k << '\n';
		return;
	}
	if(k<=(n/2)){
		cout << k << '\n';
		return;
	}
	int n2 = (n/2), k2 = ((k+n2-1)/n2)-1;
	k += k2;
	k %= n;
	k = (k==0?n:k);
	cout << k << '\n';
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while(t--) slv();
	return 0; 
}
