from sys import stdin, stdout
for _ in range(int(stdin.readline())):
    m,n=map(int,stdin.readline().split())
    zero=m-n;t=zero//(n+1);r=zero%(n+1);z=t+1
    stdout.write(str((m*(m+1))//2-(r*(z*(z+1)))//2-(n+1-r)*(t)*(t+1)//2)+'\n')