 #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;







//defines...
#define ll long long
#define tata return;
#define pb push_back
#define mp make_pair
#define in insert
#define run ios_base::sync_with_stdio(false);cin.tie(NULL);
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define vec vector<ll>
#define setl set<ll>
#define mapl map<ll,ll>
#define shunno cout<<0<<endl;
#define ek cout<<1<<endl;
#define pi 2*acos(0.0)
#define hobena cout<<-1<<endl;
  ll mod =1e9+7;
inline void norm(ll &a) {a%=mod; (a<0) && (a+=mod) ;}                            //positive mod value
inline ll modAdd(ll a,ll b) {a%=mod, b%=mod; norm(a),norm(b); return (a+b)%mod;} //modular addition
inline ll modSub(ll a,ll b) {a%=mod, b%=mod; norm(a),norm(b); return (a-b)%mod;} //modular subtraction
inline ll modMul(ll a,ll b) {a%=mod, b%=mod; norm(a),norm(b); return (a*b)%mod;} //modular multiplication
inline ll bigMod(ll b,ll p){ll r=1;while(p){if(p&1LL) r=modMul(r,b);b=modMul(b,b); p>>=1LL;}return r;}
inline ll modInverse(ll a){ return bigMod(a,mod-2);}
inline ll modDiv(ll a,ll b){ return modMul(a,modInverse(b));}

//typedefs...
typedef pair<ll,ll>pll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

//const..
const ll fx[]={0,1,0,-1};
const ll fy[]={1,0,-1,0};


//...Custom_sort.......

bool cmp(pair<ll,ll>x,pair<ll,ll>y)
{
    if(x.first!=y.first)
    {
        return x.first < y.first;
    }
    else
        return x.second < y.second;

}



ll ncr(ll n, ll k)
{
    ll res = 1;


    if (k > n - k)
        k = (n - k);

    for (ll i = 0; i < k; ++i) {
        res *= (n - i);

        res /= (i + 1);
    }

    return res;
}

ll big_mod(ll base, ll power, ll mod)
{
    if(power==0)    return 1;

    else if(power%2==1)
    {
        ll p1 = base % mod;
        ll p2 = (big_mod(base,power-1,mod))%mod;
        return (p1*p2)%mod;
    }
    else if(power%2==0)
    {
        ll p1 = (big_mod(base,power/2,mod))%mod;
        return (p1*p1)%mod;
    }
}





ll is_prime(ll x)
{
    ll i;
    for(i=2;i*i<=x;i++)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}

/*


ll a[20000010];
vec v;
void sieve()
{
    ll i,j;
    for(i=4;i<=20000000;i+=2)
        a[i]=1;
    for(i=3;i*i<=20000000;i++)
    {
        if(a[i]==0)
        {
            //cout<<i<<endl;
            for(j=i*i;j<=20000000;j+=i+i)
                a[j]=1;
        }
    }
    //yes
    for(i=3;i<=20000000;i++)
    {
       // yes

        if(a[i]==0&&a[i+2]==0)
            v.pb(i);
    }

}
*/




/*
ll f(ll n)
{
    if(n==0|r)
    else|n==1)
        retu
        return n*f(n-1);
    //cout<<f(n-1)<<endl;
}
*/

//I ain't gonna fight again.
/*class cg_average{
    double cg1=3.0,avg;
    double sum=cg1;
    ll cnt=1;
public:
    double cg2;
    void calc(double cg2)
    {
        cnt++;
        sum+=cg2;
        avg=sum/cnt;

    }
    void show()
    {
        cout<<"Your CGPA is = "<<avg<<endl;
    }






};
*/
/*
ll mem[200][202];
ll a[100];
ll dp(ll i,ll w,ll n)
{
    if(w==0)
        return 1;
    else if(i==n||w<0)
        return 0;
    ll &ret=mem[i][w];
    if(ret!=-1)
        return ret;
    return ret=dp(i+1,w-a[i],n)|dp(i+1,w,n);



}
*/
/*
ll n;
ll a[200];
ll dp[200][5];
ll f(ll i, ll x)
{
    if(i==n)
        return 0;
    ll &ret=dp[i][x];
    if(ret!=-1)
        return ret;
    if(a[i]==0)
        ret=1+f(i+1,0);
    else if(a[i]==1)
    {
        if(x==2)
        {
            ret=1+f(i+1,0);
        }
        else
            ret=min(f(i+1,2),1+f(i+1,0));
    }
    else if(a[i]==2)
    {
        if(x==1)
        {
            ret=1+f(i+1,0);
        }
        else
            ret=min(f(i+1,1),1+f(i+1,0));
    }
    else if(a[i]==3)
    {
        if(x==0)
        {
            ret=min(1+f(i+1,0),min(f(i+1,1),f(i+1,2)));

        }
        else if(x==1)
        {
            ret=min(1+f(i+1,0),f(i+1,2));
        }
        else if(x==2)
        {
            ret=min(1+f(i+1,0),f(i+1,1));
        }
    }
    return ret;


}
*/
ll po(ll n,ll k)
{
    ll i=1;
    ll ans=1;
    for(i=1;i<=k;i++)
    {
        ans*=n;
    }
    return ans;
}
ll cnt(ll n)
{
    ll i;
    i=0;
    while(n>0)
    {
        i++;
        n/=10;
    }
    return i;
}

/*
vec a[100002];
vec cost[1000002];
ll n,m;

ll dis[5000002];
void dijkstra()
{
    priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > > pq;
    pq.push({0,1});
    ll i,j;

    for(i=0;i<=n;i++)
        dis[i]=1e11;

    dis[1]=0;
    while(!pq.empty())
    {
        ll z,y;
        z=pq.top().first;
        y=pq.top().second;
        pq.pop();
       // cout<<z<<" "<<dis[y]<<endl;
        if(z!=dis[y])
            continue;
        for(i=0;i<a[y].size();i++)
        {
           // yes
            //cout<<y<<endl;
            //cout<<a[y][i]<<endl;
           // cout<<z<<" "<<cost[y][i]<<" "<<dis[a[y][i]]<<endl;
            if(z+cost[y][i]<dis[a[y][i]])
            {
               // cout<<a[y][i]<<endl;
                dis[a[y][i]]=z+cost[y][i];
                pq.push({dis[a[y][i]],a[y][i]});
                parent[a[y][i]]=y;
            }

        }
    }
    if(dis[n]==1e11)
    {
        hobena
        tata
    }

    parent[1]=1;
    ll p=parent[n];
    //cout<<p<<endl;
    vec ans;
    ans.pb(n);
  //  yes
    while(n!=1)
    {
        ans.pb(p);
        if(p==1)
            break;
        p=parent[p];


    }
    for(i=ans.size()-1;i>=0;i--)
    {
        cout<<ans[i]<<" ";
    }
    cout<<endl;




}
*/

/*
ll DP(ll n,ll k)
{
    if(k==0)
        return 1;
    ll &ret=dp[n][k];
    if(ret!=-1)
        return ret;
    if(n==9)
    {
        return ret=(DP(0,k-1)%mod+DP(1,k-1)%mod)%mod;

    }
    else
        return ret=DP(n+1,k-1)%mod;

}
*/

void oka()
{
               ll n,m,i,j,k;
               cin>>n>>m;
               ll zero,group;
               zero=n-m;
               group=m+1;
               k=zero/group;
               cout<<((n*(n+1))/2)-(k*(k+1)/2)*(group-(zero%group))-((k+1)*(k+2)/2)*zero%group<<endl;



















































































































































}





























int main()
{
//#ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin);

   // freopen("output.txt", "w", stdout);
//#endif

    run

    ll t,i,j,n;
    t=1;
    ll cas=1;
   // cout<<(2^3)<<endl;
    //cout<<(11^1)<<endl;
   // cout<<(int)'A'<<endl;







            cin>>t;

 char c;
 //cin>>c;
   //getchar();
  // cout<<__gcd(0,2)<<endl;
  //getchar();


  while(t--){
   // cout<<"Case "<<cas++<<": ";

oka();
  }
  }

