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