import sys
input = sys.stdin.buffer.readline


def s(n):
    return n * (n + 1) // 2


t = int(input())
res = []
for _ in range(t):
    n, m = map(int, input().split())
    x = s(n)
    z = n - m
    x -= z % (m + 1) * s(z // (m + 1) + 1)
    x -= (m + 1 - z % (m + 1)) * s(z // (m + 1))
    res.append(x)
print("\n".join(map(str, res)))