#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef long long ll;
#define pb push_back
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t;
cin >> t;
while(t--) {
ll n,k,total=0;
cin >> n >> k;
total = ceil((k-1)/2);
cout << total << endl;
}
return 0;
}