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

int T, N, K;

int main() {
    cin >> T;
    while(T--) {
        cin >> N >> K;

        int ans = 1;

        if(N & 1) {
            //case odd
            ans = K + (K-1)/(N/2);
            ans %= N;
        } else {
            //case even
            ans = K % N;
        }

        cout << (ans == 0 ? N : ans) << '\n';
    }

    return 0;
}
