#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
ll N, K;
cin >> N >> K;
if(K <= N ){
cout << 0 << '\n';
return;
}
ll max_product = (N - K) * N;
ll res = N, sub = 0 ;
while(true){
sub += 1;
K -= res;
//cout << N << " " << K << '\n';
max_product = max(max_product, sub * K);
//cout << max_product << '\n';
if(N == K or K < 0) break;
}
cout << max_product << '\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}
// (k/n) - x ==
// 1 6