from sys import stdin,stdout
t = int(stdin.readline().strip())
for _ in range(t):
    n,m = map(int,stdin.readline().split())
    r = max(0,(n-m*2))
    stdout.write("{}\n".format((n*(n+1)//2) - (n-m) - r*(r+1)//2 + r))
