from sys import stdin, stdout
raw_input = stdin.readline
pr = stdout.write
for t in range(input()):
    n,m=map(int,raw_input().split())
    n0=n-m
    n1=m
    x=n0-(n1)
    ans=(n*(n+1))/2
    ans-=n0
    if x>0:
        ans-=(x*(x-1))/2
    pr(str(ans)+'\n')
