

from sys import stdin, stdout
import math

q = int(stdin.readline())

for x in range(q):
    n, m = [int(x) for x in stdin.readline().split()]
    if m == 0:
        print("0")
    else:
        temp = 0


        temp = (n - m) / (m + 1)
        if temp == 1:
            temp = 0
        elif int(math.ceil(temp)) == int(temp) and temp != 0:
            #temp = (n - m) / (temp)
            temp = math.factorial(temp)
        else:
            temp = math.ceil(temp)
            temp = (temp*(temp+1))/2 - (2 - n % m)
        if temp < 0:
            temp = 0

        sum1 = ((n - 1) * n) // 2
        sum1 = int(sum1 + m) - int(temp)
        print(sum1)
    # 1: m
    # 2:
    # n: 1
    # 6 2
    # 0 1 0 0 1 0
    # 2+4+4+3+2+1 = 16   | 17
    # 4 2
    # 0 1 0 1
    # 2+3+2+1 = 8
    # 8 2
    # 0 0 1 0 0 1 0 0
    # 2 + 4 + 6 + 5 + 4 + 3 + 2 + 1 = 27    | 30
    # 4 1
    # 0 1 0 0
    # 1 + 2 + 2 + 1 = 6     |  7
    # 5 1
    # 0 0 1 0 0
    # 9 || 11
    # 5 2
    # 0 1 0 1 0 | 12
    # 6 1
    # 0 0 1 0 0 0

     # math.ceil ((n - m)/(m+1))
