from sys import stdin
input=stdin.readline
t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    nd=n//2
    if(m==0):
        print(0)
        continue
    if(m<=nd):
        k=2*m*n-6*m+4
        print(k)
    else:
        k=nd*(2*n-7)+m+4
        print(k)