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())
    z=ceil(n/2)
    ans=n*(n+1)//2
    m=n-m
    if m<=z:
        ans-=m
        print(ans)
        continue
    else:
        ans-=z
        z1=(m-z)*2
        if n==z1:
            print(0)
            continue
        else:
            ans-=z
            ans+=z1//2+1
            z1+=1
            ans-=z1*(z1+1)//2
            print(ans)
        

            
                
            
    