#define ll long long
#define dd long double
#define pb push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define fo(i ,a, n) for(ll i =a ; i < n ; i++)
//#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)//traverse through a dataset
//#define sortx(x) sort(all(x))
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll,vector<ll>,greater<ll>>
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<bitset>
ll fact[200001] ;
ll inf=1e18;
ll z=1e9+7;
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ;    return (a - (a%b)) ;} // greatest number <= a divisible by b
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
ll x1 , y1 ; e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return e_gcd(b , a%b , x1 , y1) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
ll ncr(ll n , ll r){if(n < r|| (n < 0) || (r < 0)) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
void swap(char&a , char&b){char c = a ; a = b ; b = c ; return ;}
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define ub(v,x) upper_bound(v.begin(),v.end(),x);
#define lb(v,x) lower_bound(v.begin(),v.end(),x);
dd pi = acos(-1) ;
ll pow(ll a ,ll b ){if(b == 0) return 1 ; ll c = pow(a , b/2) ; if(b%2 == 0) return (c*c) ; else return ((c*c)*a);}
 
using namespace std ;
const int N = 1e6+7;
const int M=1e3+7;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> */
vector<ll>adj[N];
//int mat[N][N];
//vector<bool>used(N,false);
//vector<ll>d(N,-1);
//vector<ll>p(N,-1);
 /*
bool cmp(ll a,ll b){
   return b<a;
}*/
/*ll visited[N];
void dfs(ll s){
   for(auto x:adj[s]){
      if(visited[x]==0){
      visited[x]=1;
      dfs(x);
      }
      
   }
   
}
*/
struct S
{
    int m_n1;
    int m_n2;
    int m_n3;
 
    S(int n1, int n2, int n3) : m_n1(n1), m_n2(n2), m_n3(n3)
    {
    }
 
    bool operator<(const struct S& other) const
    {
        if(m_n1!=other.m_n1)
        return m_n1 < other.m_n1;
        else
        return m_n2 > other.m_n2;
    }
};

bool check(string a,string b){
    if(a==b)
     return true;
    else
      return false;
}

void solve(){
  ll n,k;
  cin>>n>>k;
  ll ans;
  if(n%2==0){
    
    if(k%n==0){
      ans=n;
    }
    else{
      ans=k%n;
    }
  }
  else{
    ll temp=k;
    ll val=(n+1)/2;
    k=k-k/val;
    if(temp%(val-1)==0)
       k=(temp/(val-1))-1;
    else
       k=temp/(val-1);
   k=temp+k;
   if(k%n==0){
    ans=n;
   }
   else{
    ans=k%n;
   }
  }
  cout<<ans<<endl;
} 
 int main()
{
      #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
      ios_base::sync_with_stdio(false);
     cin.tie(NULL);

    

     ll t;
    
    cin>>t;
    while(t--){
    solve();
     }
  }