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 = min( n, (2*m+1) )
        ans.append( str(nc2(k)+m) )
stdout.write('\n'.join(ans))