import sys


def input(): return sys.stdin.readline().rstrip()


t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    per = (n*(n+1))//2
    count0 = n-m
    nG = m+1
    k = count0//nG
    rem = count0//nG
    val = per - (rem*(rem+1))//2*nG - (k+1)*(count0 % nG)
    print(val)
