#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll ;
//typedef __int128 lll;
#define pb push_back
#define pinf 2e18
#define ninf -2e18
#define PI acos(-1.0)
#define endl "\n"
#define F first
#define S second
//template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//inout() ;
ll t;
cin>>t;
while(t --){
ll n,k;
cin>>k>>n;
ll x=n%(k+1);
n-=x;
n/=(k+1);
x=x+(n);
cout<<x*n<<'\n';
}
return 0 ;
}