#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int, pi> pii;

const int maxn = 200010;
const int INF = LLONG_MAX/2;
const int mod = 1e9+7;

void solve() {
	int n, k; cin >> n >> k;
	
	if (n % 2 == 0) {
		k--;
		k %= n;
		cout << k+1 << "\n";
		return;
	}
	
	int grp = n/2;
	int grpsz = grp * n;
	
	k--;
	k %= grpsz;
	
	int curg = k / grp;
	int m = (1 + (grp+1) * curg);
	m--;
	m %= n;
	m++;
	//while (m > n) m -= n;
	
	//cout << k << " " << curg << " " << m << "\n";
	
	m += (k - curg * grp);
	if (m > n) m -= n;
	
	cout << m << "\n";	
}

int32_t main() {
	FAST
	int tc; cin >> tc;
	while (tc--) solve();
}




