#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long 
#define qc std::ios::sync_with_stdio(0);
signed main() {
	qc;
	cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		if (n % 2 == 0) {
			int temp = k%n;
			if (temp == 0)temp = n;
			cout << temp << endl;
		}
		else {
			int w = n / 2;
			int temp;
			temp = k + (k-1) / w;
			temp = temp % n;
			if (temp == 0)temp = n;
			cout << temp << endl;
		}

	}
	return 0;
}
