#include<iostream>

using namespace std;

int main()
{
    int t; 
    cin >> t;
    while (t--)
    {
        long long n,k; 
        cin >> n >> k;
        if (n%2==0)
        {
            if (k%n == 0) 
            {
                cout << n << endl;
            }
            else 
            {
                cout << k%n << endl;
            }
        }
        else
        {
            long long x = 1+(n/2);
            k = k%((x-1)*n);
            if (k == 0) cout << n-1 << endl;
            else
            {
                if (k<n)
                {
                    if (k<x) cout << k << endl;
                    else cout << k+1 << endl;
                }
                else
                {
                    k = k-(n-1);
                    long long t,m;
                    if (k%(n-2)==0)
                    {
                        cout << n << endl;
                        continue;
                    }
                    else
                    {
                        t = k%(n-2);
                        m = (k/(n-2))+1;
                    }
                    if (t>=m) 
                    {
                        t++;
                    }
                    if (t>=x+m) 
                    {
                        t++;
                    }
                    cout << t << endl;
                }
            }
        }
    }
}