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

int main()
{
#ifndef ONLINE_JUDGE
	//FOR GETTING INPUT FROM INPUT.TEXT
	freopen("input", "r", stdin);
	//for getting output to output.txt
	freopen("output", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		long long n, k;
		cin >> n >> k;
		if (n % 2 == 0)
		{
			if (k % n == 0)
			{
				cout << n << endl;
			}
			else
			{
				cout << k % n << endl;
			}
		}
		else
		{
			long long packet = n * (n / 2);
			long long p = k % packet;
			if (p == 0)
			{
				cout << n - 1 << endl;
			}
			else if (p < n)
			{
				if (p < n / 2 + 1)
				{
					cout << p << endl;
				}
				else
				{
					cout << p + 1 << endl;
				}
			}
			else
			{
				p = p - (n - 1);
				long long x = p / (n - 2);
				x = x + 1;
				long long t = p % (n - 2);
				if (t == 0)
				{
					cout << n << endl;
				}
				else
				{
					if (t < x)
					{
						cout << t << endl;
					}
					else if (t == x + n / 2 + 1 - 1)
					{
						cout << x + n / 2 + 2 << endl;
					}
					else if (t >= x + n / 2 + 1)
					{
						cout << t + 2 << endl;
					}
					else
					{
						cout << t + 1 << endl;
					}
				}

			}


		}
	}
	return 0;
}

