t = int(input())
ans = []
for kek in range(t):
    (n, m) = map(int, input().split())
    ans2 = 0
    if m == 0:
        ans2 = 0
    else:
        k = int((n+1)/(m+1))
        ans2 += m*(k+1)*k//2
        ans2 += (n-k)*(1+n-k)//2
    ans.append(ans2)
print(*ans)