outs = []
for _ in range(input()):
    N,ones = map(int,raw_input().split())
    zeros = N - ones
    zeros_len0 = zeros / (ones + 1)
    zeros_len1 = zeros_len0 + 1
    no_len1 = zeros - zeros_len0 * (ones + 1)
    no_len0 = ones + 1 - no_len1
    non_succ0 = no_len0 * zeros_len0 * (zeros_len0 + 1) / 2
    non_succ1 = no_len1 * zeros_len1 * (zeros_len1 + 1) / 2
    tot = N * (N + 1) / 2
    outs.append(tot - non_succ0 - non_succ1)
print '\n'.join(map(str,outs))
