import sys
for _ in range(int(input())):
    n, m = map(int, sys.stdin.readline().split())   
    total = (n * (n + 1)) // 2
    if m >= n//2: 
        total -= (n - m)
    else:
        t = n - m
        d = m + 1
        r = t % d
        x = t // d
        s = d - r
        total -= (r*(x+1)*(x+2)//2 + s*(x)*(x+1)//2)
    print(total)
