import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
z = int(readline())
for _ in range(z):
    #n:文字列全体の長さ(<10**9),m:1を含む数
    n,m = map(int,readline().split())
    
    G = m+1
    Z = n-m
    k,rest = divmod(Z,G)

    print((n*(n+1))//2 - (G*(k*(k+1)//2)+ (k+1)*rest ))



