t = int(input())
C = [list(map(int,input().split())) for i in range(t)]

# t = 10**5
# C = [[523422132331, 102342223434] for i in range(t)]

def c(x, y):
    if x % 2 == 0:
        return (x//2) * y
    else:
        return (y//2) * x

for i in range(t):
    n = C[i][0]
    o = C[i][1]
    z = n-o
    al = c(n, (n-1)) + n
    # print("al",al)
    if z-1 <= o:
        print(al - z)
        # v=0
    else:
        a = z // (o+1)
        b = z % (o+1)
        # print(a,b)
        mi = c((a+1), (a+2)) * b + c(a, (a+1)) * (o+1-b)
        print(al - mi)

