# include <bits/stdc++.h>
using namespace std;
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		int n, k;
		cin >> n >> k;
		if (n % 2 != 0)
		{
			if (k - 1 != 0)
			{
				if ((k + (k - 1) / (n / 2)) % n != 0)
				{
					cout << (k + (k - 1) / (n / 2)) % n << endl;
				}
				else cout << n << endl;
			}
			else cout << 1 << endl;
		}
		else
		{
			if (k % n != 0)
			{
				cout << k % n << endl;
			}
			else cout << n << endl;
		}
	}
	return 0;
}