#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int a, b, ans;
cin >> a >> b;
if (b == 0) {
cout << a << endl;
continue;
}
if (a < b) {
cout << 0 << endl;
continue;
}
int l = 1, r = 1e14;
while (l < r) {
int mid = l + r >> 1;
if (a / mid <= b) {
r = mid;
} else {
l = mid + 1;
}
}
ans = l;
l = 1, r = 1e14;
while (l < r) {
int mid = l + r + 1 >> 1;
if (a / mid < b) {
r = mid - 1;
} else {
if (a / mid > b)
l = mid + 1;
else
l = mid;
}
}
ans = l - ans + 1;
cout << ans << endl;
}
return 0;
}