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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(false); 
    cin.tie(0); 

    int t;
    cin >> t;
    while(t--) {
    	int n, k;
    	cin >> n >> k;

    	// if n is even then they will never conflict
    	if(n % 2 == 0) {
    		cout << ((k - 1)) % n + 1 << endl;
    	} else {
    		int index = ((k - 1)) % n + 1 ;
    		int ups = (k - 1) / (n / 2);
    		index += ups; index--;
    		index %= n; index++;
    		if(index == 0) {
    			index++;
    		}
    		cout << index << endl;
    	}
    }
    return 0;
}
