t = int(input())

while t:
    n,m= [int(i) for i in input().split()]
    tot = (n*(n+1))//2
    if n-m>=m:
        remains = n-2*m
        ans = tot-(m+((remains*(remains+1))//2))
        print(ans)
        
    else:
        print(tot-(n-m))
    
    t-=1