#include <bits/stdc++.h>
#define int long long
#define endll '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int mod = 1e9 + 7, N = 1e6;
unordered_map<int, int> vis;
void solve()
{
vis.clear();
int n, k;
cin >> n >> k;
int L = 0, R = (k) / n;
// cout << R << endl;
// cout << "Greedy = " << R * (k - (R * n)) << endl;
int ans = 0;
while (L <= R)
{
int M = (L + R) / 2;
int value = M, K = k - (M * n);
if (value > K)
{
R = M - 1;
}
else
{
ans = max(ans, M);
L = M + 1;
}
}
for (int i = max(0LL, ans - 100000); i <= ans + 100; i++)
{
int value = i, K = k - (i * n);
if (K <= 0)
break;
// cout << i << " , " << value * k << endl;
ans = max(ans, value * K);
}
cout << ans << endll;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}