import sys
get = lambda x: x*(x+1)//2
t = int(sys.stdin.readline())
for _ in range(t):
    n, m = map(int, sys.stdin.readline().split(" "))
    all = get(n)
    zeros = n-m
    len_complete_intervals = zeros // (m+1)
    len_remained_intervals = zeros % (m+1)
    print( all - get(len_complete_intervals)*(m+1) - (len_complete_intervals+1)*len_remained_intervals )
