from sys import stdin, stdout


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


def bs(be, en):
    while (be < en):
        mid = (be + en) // 2
        val = m * mid

        if val >= (n - (mid - 1)):
            en = mid
        else:
            be = mid + 1
    return en


def arr_inp(n):
    return [int(x) for x in stdin.readline().split()]


t = int(input())
ans, arr = [], [arr_inp(1) for i in range(t)]

for n, m in arr:
    if m == 0:
        ans.append('0')
    else:
        tem = bs(1, n)
        val = sum_range(n - tem + 1) + m * sum_range(tem - 1)
        ans.append(str(val))

print('\n'.join(ans))
