//a+b = (a^b) + 2*(a&b)
//b^c = (a^b)^(a^c) 
//gcd(x,y) = gcd(x-y,y)
//check for long long overflow if input is large
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define mod 1000000007
//#define mod 998244353
#define pb push_back
#define ll long long
#define fi first
#define se second
#define vi vector<int> 
#define pii pair<int,int>
#define mii map<int,int>
#define loop(i,n) for(int i=0;i<n;i++) 
#define pp  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) 
#define fill(a,b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
 
#define en cout<<"\n"

#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long INF = 2000000000000000000;

long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans; 
}

void solve()
{
	int n,m;
	cin>>n>>m;
	if(m>=n/2)
	{
		int ans;
		if(n%2==0)
		{
			ans = (n/2)*(n);
			cout<<ans + m - n/2;
		}
		else
		{
			int t = n/2;
			ans = (t)*(2*t + 2);
			cout<<ans + m-n/2;
		}
	}
	else
	{
		int ans;
		if(n%2==0)
		{
			ans = (n/2)*(n);
			cout<<ans - (n/2-m)*(n/2-m)*2;
		}
		else
		{
			int t = n/2;
			ans = (t)*(2*t + 2);
			int ans1 = t - m;
			ans1 = (ans1)*(2*ans1 + 2);
			cout<<ans - ans1;
		}
	}
}
int32_t main() 
{
pp;
int test=1;
cin>>test;
while(test--)
{
	solve();
	en;
}
return 0 ;
}