from sys import stdin, stdout

t = input()
inp = stdin.readlines()
out = []

for line in inp:
    n, m = map(int, line.strip().split())
    q = (n + 1) / (m + 1)
    r = (n + 1) % (m + 1)

    tot = (n * (n + 1)) / 2
    sub = (r * q * (q + 1)) / 2 + (q * (q - 1) * (m + 1 - r)) / 2
    x = tot - sub

    out.append(str(x))
stdout.write("\n".join(out))
