#include <bits/stdc++.h>
using namespace std;
void FastCode()
{
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void solve(){
long long n , k;
cin >> n >> k;
if(n == 1){
if(k == 2) cout<<"1\n";
else cout<<"0\n";
return;
}
int ans = (k-1)/2;
if(k%2 == 0) ans++;
cout<<ans<<"\n";
}
int main()
{
FastCode();
int t;
cin >> t;
while(t--) solve();
return 0;
}