import sys
t=int(sys.stdin.readline())
for _ in range(t):
    n,m=map(int,sys.stdin.readline().split())
    if m==0:
        print(0)
    else:
        if m>=(n+1)//2:
            print(n*(n+1)//2-(n-m))
        else:
            x=2*m
            #print(x,'x')
            ans=((x*(x+1))//2-(m))
            #print(ans,'ans 2')
            if (n-x)%2==0:
                left,right=(n-x)//2,(n-x)//2
            else:
                left,right=(n-x)//2,(n-x)//2
                right+=1
            #print(left,'left',right,'right')
            ans+=x*(right)
            ans+=left*(n-(left+1))
            print(ans)
