t=int(input())
def fonction(n,m):
    if m==0:
        return 0
    elif m==n:
        return n*(n+1)//2
    elif (n%2==0) and (m==1):
        return ((n-m-1)//2+1)*((n-m-1)//2+1)+((n-m-1)//2+1)
    elif (n%2==1) and (m==1):
        return ((n-m)//2+1)*((n-m)//2+1)
    
        
    else:
        return( n*(n+1)//2)-(n-m)
L=[]
for i in range(t):
    n,m=[int(x) for x in input().split()]
    L.append(fonction(n,m))
for k in L:
    print(k)