import math
t = int(input())
while t > 0:
    n, m = [int(ele) for ele in input().split()]
    if m < math.ceil(n/2):
        nn = 2*m
        count0 = nn-m
        rem = n-nn
        count0 += int((rem*(rem+1))/2)
        per = int((n*(n+1))/2)
        print(per - count0)

    elif m == math.ceil(n/2):
        nn = 2*m-1
        count0 = nn-m
        rem = n-nn
        count0 += int((rem*(rem+1))/2)
        per = int((n*(n+1))/2)
        print(per-count0)

    else:
        rem = n-m
        print(rem)
        per = int((n*(n+1))/2)
        print(per-rem)
    t -= 1
