import sys
input=sys.stdin.readline
from math import *
t=int(input())
while(t):
 t-=1
 n,m=map(int,input().split())
 if(m==0):
  print(0)
  continue
 if(m>=n//2):
  x=n-m
  y=n*(n+1)
  y=y//2
  print(y-x)
  continue
 x=m
 y=n*(n+1)
 y=y//2
 rem=n-(m*2)
 rem=rem*(rem+1)
 rem=rem//2
 x+=rem
 print(y-x)
   
  
