#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("unroll-loops")

#define dbg(x) cerr << #x << " = " << x << "\n"
#define all(x) x.begin(), x.end()
#define pb push_back
#define se second
#define fi first
#define sz(a) int(a.size())

#define fr(i,l,r) for(ll i=l;i<=r;++i)
#define rf(i,l,r) for(ll i=l;i>=r;--i)

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;

typedef pair<ll,ll> pll;

const int N = 1e6+10;
const ll oo=1e18;

mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

map<ll,ll> id;
ll mp[N],a[N];
ll n,m,ans=0;

ll func(ll x, ll y, ll z){
    return x*(y+1)*y/2+(z+1)*z/2;
}

ll calc(ll n, ll x){
    if(x==0)return 0;
    ll ans=(n+1)*n/2;
    ll z=n%x;
    ll k=n/x-1;
    ll w=func(x,k,z);

    ll timer=0;
    for(;k>=0;--k){
        timer++;
        if(timer>100||x!=n/(k+1))break;

        x=n/(k+1);
        z=n-x*(k+1);
        w=min(w,func(x,k,z));
        //cout<<"w="<<w<<"x="<<x<<"k="<<k<<"z="<<z<<endl;

    }
    //cout<<"w="<<w<<endl;
    ans-=w;
    return ans;
}

int main() {
    ll t;
    cin>>t;
    fr(z,1,t){
ll n,x;
        cin>>n>>x;
        cout<<calc(n,x)<<"\n";

    }
    return 0;
}
/*
1
abacad
*/
