#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;
vector<ll> bags;
for(ll i=1; i<k; i++) {
bags.pb(i);
}
const int size = bags.size()/2;
for(int i=0; i<size; i++) {
for(int j=1; j<bags.size(); j++) {
if(bags[0]+bags[j]==k){
total++;
bags.erase(bags.begin()+j);
bags.erase(bags.begin());
break;
}
}
}
if(!bags.empty())total++;
cout << total << endl;
}
return 0;
}
Copy