import sys
input = sys.stdin.readline

def gettotal(n):
    return (n*(n+1))//2

for _ in range(int(input())):
    n,m = map(int,input().split())
    # if m == 0:
    #     sys.stdout.write(str(0) + "\n")
    #     continue

    div = m+1
    rem = n-m
    ad = rem//div
    first = rem%div
    fl = ad+1
    fn = first
    sl = ad
    sn = div-first
    # print("fl",fl,"fn",fn,"sl",sl,"sn",sn)
    total = gettotal(n)
    sub = (gettotal(fl)*fn)+(gettotal(sl)*sn)
    sys.stdout.write(str(total-sub)+"\n")