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