/**
* written by Binoy Barman .
**/
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define int long long
int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
Too_Many_Jobs {
int n, k;
cin >> n >> k;
if (n >= k) {
cout << 0 << nl;
goto hell;
}
int L = 1, H = k, mid, ans = 0, ans2 = 0;
while (L <= H) {
mid = (L + H) >> 1;
if (mid + (mid * n) > k) {
H = mid - 1;
}
else {
ans2 = max(ans2, (mid + (k - (mid + (mid * n)))) * mid);
ans = mid;
L = mid + 1;
}
}
int x = ans + (k - (ans + (ans * n))), y = ans;
dbg(k, ans, x, y, x * y);
cout << max({x * y, (x + n) * (y - 1), ans2}) << nl;
}
return 0;
}