t=int(input())
def fonction(n,m):
    if m==0:
        return 0
    elif m==n:
        return n*(n+1)//2
    elif (n==2) and (m==1):
        return 2  
    elif (n==3) and(m==1):
        return 4
    elif ((n-m)%2==0) and (m==1):
        return (n-m)+2*((n-m)//2-1)+3
    elif ((n-m)%2==1) and (m==1):
        return (n-m)+(n-m-1)+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)