#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ll long long
int main() {
IOS
int t;cin>>t;
while(t--){
int n,k;cin>>n>>k;
cout<<ceil(--k/2.0)<<"\n";
}
}