from sys import stdin, stdout
input = stdin.readline
pr = stdout.write
for _ in range(int(input())):
    n, m = map(int, input().split())
    k = n - m
    a = k // (m + 1)
    b = k % (m + 1)
    pr(str(n * (n + 1) // 2 - (m + 1 - b) * (a * (a + 1) // 2) - b * ((a + 1) * (a + 2) // 2)) + '\n')