#include <bits/stdc++.h>
using namespace std;
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef vector<ll> vi;
typedef long double ld;
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define mp make_pair
#define bits(x) __builtin_popcountll(x)
#define endl "\n"
#define M 998244353
#define mod 1000000007
ll binToDec(string s) { return bitset<64>(s).to_ullong(); }
string decToBin(ll a) { return bitset<64>(a).to_string(); }
void solve() {
int T;
cin >> T;
while (T--){
// Read N and K for the test case.
long long N, K;
cin >> N >> K;
// If we can't even give each element one increment,
// the AND remains 0, so answer is 0.
if(K < N){
cout << 0 << "\n";
continue;
}
long long max_v = K / N;
// The function f(v) = K*v - N*v*v is concave and
// its continuous maximum is at v = K / (2*N).
long long candidate1 = K / (2 * N);
if(candidate1 < 1) candidate1 = 1; // ensure at least 1.
long long candidate2 = candidate1 + 1;
auto f = [&](long long v) -> long long {
return v * (K - N * v);
};
long long ans = f(candidate1);
if(candidate2 <= max_v){
ans = max(ans, f(candidate2));
}
cout << ans << "\n";
}
}
int main(){
auto begin = std::chrono::high_resolution_clock::now();
ios::sync_with_stdio(false);
cin.tie(0);
ll test=1;
// cin>>test;
for(int i=1;i<=test;i++) {
//cout << "Case #" << i << ": ";
solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
}