import sys
input = sys.stdin.readline
for l in range(int(input())):
    n, m = map(int, input().split(" "))
    zerosPer = (n-m)//(m+1)
    numUpper = (n-m)%(m+1)
    x = (m+1-numUpper)*(zerosPer)*(zerosPer+1)//2
    x = x + numUpper*(zerosPer+1)*(zerosPer+2)//2

    print(n*(n+1)//2-x)
    
