

import sys
inf = 1 << 64


def input():
    return sys.stdin.readline().rstrip()


def slv():
    n, m = map(int, input().split())
    u, v = divmod(n - m, m + 1)
    ans = n * (n + 1)//2 - v*(u + 1)*(u + 2)//2 - (m + 1 - v)*u*(u + 1)//2
    print(ans)
    return


t = int(input())
for i in range(t):
    slv()
