import math

n = int(input())
Result = []

for i in range(0,n):
    
    List = list(map(int,input().strip().split()))[:2]
    
    len_ = List[0]
    N1 = List[1]
    N0 = List[0] - List[1]

    if N1 > 0:
        Sandwich_N0 = N1 - 1
        Series_N0 = N0 - Sandwich_N0
        Split_a_0 = math.floor(Series_N0/2)
        Split_b_0 = Series_N0 - Split_a_0
    else:
        Sandwich_N0 = 0
        Series_N0 = N0
        Split_a_0 = N0
        Split_b_0 = 0
    
    if N0 <= N1 :
        Result.append( int(len_*(len_-1)/2) + N1 )
    else:
        Result.append( int(len_*(len_-1)/2) + N1 - int(Split_a_0*(Split_a_0-1)/2) - int(Split_b_0*(Split_b_0-1)/2) )

for i in Result:
    print(i)