#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define ull unsigned long long
#define lim2 10000007
int cs = 1;
long long lim = 1e12 + 8;
using namespace std;

void file();
int dx[] = { 0, 0, +1, -1 };
int dy[] = { +1, -1, 0,  0 };


bool valid(int r, int c,int n,int m)
{
    return (r >= 0 && r < n && c >= 0 && c < m ) ;

}

///////////////////////////// topic: (    )+(    )



void solve()
{


    ll n,k;
    cin>>n>>k;

    if (n&1)
    {
        ll hlf=n/2;

        ll tem= (k-1)/hlf;

        k+=tem;

        if (k%n==0) cout<<n<<endl;
        else cout<<k%n<<endl;




    }
    else if (k%n==0) cout<<n<<endl;
    else cout<<k%n<<endl;


}

int main()
{

    int t;
    scanf("%d",&t);
    while(t--)
        solve();




    return 0;
}

void file()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
