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-rem)*mul*(mul+1)//2 - rem*(mul+1)*(mul+2)//2
    stdout.write(str(ans)+'\n')