#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using ll = long long;
int main() {
FAST;
int tc = 1, ti;
cin >> tc;
for (ti = 1; ti <= tc; ++ti) {
ll n, k, i, t, l, r, mid1, mid2, ans1, ans2, ans;
cin >> n >> k;
l = 0; r = (1 << 30);
t = 60; while (t--) {
mid1 = l + (r-l)/3;
mid2 = r - (r-l)/3;
ans1 = mid1 * (k - mid1*n);
ans2 = mid2 * (k - mid2*n);
if (ans1 > ans2) {
r = mid2;
} else {
l = mid1;
}
}
ans = 0;
for (i = l; i <= r; ++i) {
ans = max(ans, i * (k - i*n));
}
cout << ans << "\n";
}
return 0;
}