def total(k): return (k*(k+1)) // 2
ans = []
for _ in range(int(input())):
    n, m = tuple(map(int,input().split()))
    if m==0:
        ans.append( str(0) )
    else:
        al = total(n)
        zeros = n-m
        #divide into m+1 groups
        grp_size = zeros//(m+1)
        extra_grp = zeros%(m+1)
        zero_blocks = m*total(grp_size) + total(grp_size + extra_grp)
        ans.append(str(al-zero_blocks))
print(*ans,sep="\n")