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-2*m
    print((n*(n+1))//2-m-(r*(r+1))//2)