from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
    n,m = list(map(int,(stdin.readline()).split()))
    total = 0
    if n//2>m:
        diff = (n//2)-m +1
        x = n-diff
        l = n -(diff+2*m -1)
        total = (diff-1)*(x) + ((x*(x+1))//2) -((l*(l-1))/2) + m
    else:
        total = (n*(n-1))//2 + m
    if m == 0:
        total = 0
    stdout.write(str(int(total))+'\n')
    