from sys import stdin, stdout
def nc2(k): return (k*(k-1))//2
t = int(stdin.readline())
ans = []
for line in stdin:
    n, m = tuple(map(int,line.split()))
    if m==0:
        ans.append( str(0) )
    else:
        k = (2*m)-1 
        if k >= n:
            ans.append( str( nc2(n)+m ) )
        else:
            remain = n - k
            if remain%2==0:
                a = remain//2
                ans.append( str((2*a*k) + nc2(k) + m + a*a) ) 
            else:
                a,b = remain//2, (remain+1)//2
                ans.append( str(a*k + b*k + nc2(k) + m + a*b) )
stdout.write('\n'.join(ans))