import math
import collections
import sys


def inpu():
    return input().split(' ')


def inti(a):
    for i in range(len(a)):
        a[i] = int(a[i])
    return a


def inp():
    a = inpu()
    a = inti(a)
    return a


def solution():
    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)


for _ in range(int(input())):
    solution()
