#include <iostream>
using namespace std;
int size= 100001;
int main() {
int Test;
cin>>Test;
while(Test>0){
int ans;
int n;
int k;
cin>>n;
cin>>k;
if(k/2==n){
ans = 1;
}
else if(k/2>n){
ans = 0;
}
else{
ans = k/2;
}
cout<<ans<<endl;
ans = 0;
Test--;
}
}