import sys
input=sys.stdin.readline
t=int(input())
for _ in range(t):
  n,m=map(int,input().split())
  if m>=n-m+1:
    print((n*(n+1))//2-n+m)
  else:
    r=n-m-max(m-1,0)
    r1=r//2
    r2=r-r1
    if m>0:
      print((n*(n+1))//2-(m-1)-(r1*(r1+1))//2-(r2*(r2+1))//2)
    else:
      print(0)