for u in range(int(input())):
    n,m=map(int,input().split())
    if m==0:
        print("0")
        continue
    if m==n-m:
        print((n*(n+1))//2-n//2)
    elif m>n-m:
        k=n-m
        print((n*(n+1))//2-k)
    else:
        k=((n-m)%(m+1)+1)
        ans=n*(n+1)//2-k*(k+1)//2-m
        print(ans)