#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
void MOUST(){
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int main(){
MOUST();
int q;cin>>q;
while(q--){
ll n,k;cin>>n>>k;
if(n+1==k)
cout<<n/2<<"\n";
else
cout<<"0\n";
}
}