from sys import stdin, stdout
t=int(stdin.readline())
while t:
    t-=1
    n,m = map(int , stdin.readline().split())
    mul,rem = divmod(n-m, m+1)
    ans = (n*(n+1))//2 - (m+1)*(mul*(mul+1)//2) - rem*(rem+1)//2
    stdout.write(str(ans)+'\n')