def solve():
    import sys
    t = int(input())
    while (t > 0):
        n, m = [int(x) for x in sys.stdin.readline().split()]
        g = m + 1
        z = n - m
        k = z//g
        print((n*(n+1))//2 - (k*(k+1)*g)//2 - (k+1)*(z % g))
        t -= 1


solve()
