import sys
t = int(input())
for T in range(t):
    n, m = [int(x) for x in sys.stdin.readline().split()]

    ans = (n * (n + 1)) // 2
    val = (n - m) // (m + 1)
    ans -= val * (val + 1) * (m + 1) // 2
    rem = (n - m) % (m + 1)
    ans -= (val + 1) * rem

    print(ans)
