#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define all(v) v.begin(), v.end()
#define pb push_back
#define sz(x) (int)(x).size()
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cout << vars << " = ";
string delim = "";
(..., (cout << delim << values, delim = ", "));
cout << '\n';
}
inline void solve() {
int n, k;
cin >> n >> k;
cout << max(0, (k - 1) / 2) << '\n';
}
int main() {
// freopen("calc.in", "r", stdin);
// freopen("in.txt", "w", stdout);
cin.tie(0)->sync_with_stdio(0);
int T = 1;
cin >> T;
while(T--) {
solve();
}
}
Copy