"""
NTC here
"""
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
flush= sys.stdout.flush
# import threading
# setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(input())
def lin(): return list(map(int, input().split()))

# range = xrange
# input = raw_input

def main():
    # from bisect import bisect_right as br
    T = iin()
    def fn(n):
        return ((n)*(n+1))//2
    while T:
        T-=1
        n, m = lin()
        ans = fn(n)
        dl = 0
        bx = m+1
        zo = n-m
        x = zo//bx
        x1 = zo%bx
        x2 = bx-x1
        dl = fn(x)*x2+fn(x+1)*x1
        print(ans-dl)






             



















        
main()
#threading.Thread(target=main).start()