def go():
    n,m = map(int, raw_input().split())
    z = n-m
    zg,rg = z//(m+1), z%(m+1)
    #zg x (m+1-rg)
    #(zg+1) x (rg)
    tot = n*(n+1)//2
    sm = zg*(zg+1)//2
    lg = (zg+1)*(zg+1+1)//2
    return str(tot - sm*(m+1-rg) - lg*rg)

def run():
    t = int(input())
    res = []
    for _ in range(t):
        res.append(go())
    print ('\n'.join(res))

run()