def fastio():
	import sys
	from io import StringIO 
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

from math import ceil
for _ in range(int(input())):
    n,m=map(int,input().split())
    half=ceil(n/2)
    ans=n*(n+1)//2
    zero=n-m
    if zero<=half:
        ans-=zero
        print(ans)
    else:
        m-=1
        ans=m*(m+1)*(2*m+1)//3+3*m*(m+1)//2+m+1
        print(ans)
        
    