#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0)
int t;
long long n, k;
cin >> t;
while (t--)
{
cin>>n>>k;
if(k>=n+1)
cout<<(n+1)/2<<endl;
else
{
cout<<k/2<<endl;
}
}
return 0;
}