from sys import stdin

input = stdin.readline

for _ in range(int(input())):
    a, b = list(map(int, input().split(" ")))
    extra = 0
    total = a * (a + 1) // 2
    if b >= a//2 + a%2:
        print(total - (a-b))
    else:
        x = a-b
        v1 = (a-b)//(b+1)
        v2 = (a-b)%(b+1)
        total -= (v2*(v1+1)*(v1+2)//2 + (b+1 - v2)*(v1+1)*(v1)//2)
        print(total)
