You are given two integers n and m. You have to construct the array a of length n consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly m and the value ∑_{i=1}^{n-1} |a_i - a_{i+1}| is the maximum possible. Recall that |x| is the absolute value of x.

In other words, you have to maximize the sum of absolute differences between adjacent (consecutive) elements. For example, if the array a=[1, 3, 2, 5, 5, 0] then the value above for this array is |1-3| + |3-2| + |2-5| + |5-5| + |5-0| = 2 + 1 + 3 + 0 + 5 = 11. Note that this example doesn't show the optimal answer but it shows how the required value for some array is calculated.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow.

The only line of the test case contains two integers n and m (1 ≤ n, m ≤ 10^9) — the length of the array and its sum correspondingly.

Output

For each test case, print the answer — the maximum possible value of ∑_{i=1}^{n-1} |a_i - a_{i+1}| for the array a consisting of n non-negative integers with the sum m.

Example

Input


5
1 100
2 2
5 5
2 1000000000
1000000000 1000000000


Output


0
2
10
1000000000
2000000000

Note

In the first test case of the example, the only possible array is [100] and the answer is obviously 0.

In the second test case of the example, one of the possible arrays is [2, 0] and the answer is |2-0| = 2.

In the third test case of the example, one of the possible arrays is [0, 2, 0, 3, 0] and the answer is |0-2| + |2-0| + |0-3| + |3-0| = 10.

'''test=int(input())
for i in range(test):
    a,b,c,d=[int(i) for i in input().split(" ")]
    x,y,x1,y1,x2,y2=[int(i) for i in input().split(" ")]
    ans1=0
    ans2=0
    if abs(x-x1)>=a and abs(x2-x)>=b:
        ans1=1
    elif abs(x-x1)>=a:
        if abs(x2-(x-a))>=b:
            ans1=1
    elif abs(x2-x)>=b:
        if abs(x+b-x1)>=a:
            ans1=1
    if abs(y-y1)>=c and abs(y2-y)>=d:
        ans2=1
    elif abs(y-y1)>=c:
        if abs(y2-(y-c))>=d:
            ans2=1
    elif abs(y2-y)>=d:
        if abs(y+d-y1)>=c:
            ans2=1
    
    if ans1&ans2:
        print("YES")
    else:
        print("NO")'''

'''b=int(input())
s1=[int(i) for i in input().split(' ')]
g=int(input())
s2=[int(i) for i in input().split(" ")]
s1.sort()
s2.sort()
ans=0
for i in range(b):
    for j in range(g):
        if abs(s1[i]-s2[j])<=1:
            s2[j]=1000
            ans+=1
            break
print(ans)
'''

#CF 639

'''test=int(input())
for i in range(test):
    n,m=[int(i) for i in input().split()]
    if n==1:
        print("YES")
    elif '''


'''test=int(input())
def value(t):
    return (t*(3*t+1))/2
def f(x):
    if x<2:
        return 0
    elif x==2:
        return 1
    else:
        h=1
        k=2
        
        while k<=x:
            h+=1
            k=value(h)
        card_used=value(h-1) if k!=x else k
        return 1+f(x-card_used)

for i in range(test):
    n=int(input())
    
    ans=f(n)
    #print(value(4))
    print(ans)  
    '''

#CF  640 (DIV-4)

'''test=int(input())
for i in range(test):
    n=int(input())
    ans=[]
    c=0
    while n:
        k=10**(c)
        ans.append((n%10)*k)
        c+=1
        n=n//10
    tes=[i for i in ans if i]
    print(len(tes))
    for j in tes:
        print(j,end=" ")'''

'''test=int(input())
for i in range(test):
    n,k=[int(i) for i in input().split()]'''


'''test=int(input())
for i in range(test):
    n,k=[int(i) for i in input().split()]
    jump=n-1
    if k<n:
        rank=k
    else:
        rank=k+int((k-1)//(n-1)) 
    
   
    print(rank)'''



'''test=int(input())
for i in range(test):
    n=int(input())
    arr=[int(i) for i in input().split()]
    i=-1
    j=n
    rem=n
    alice=0
    bob=0
    prev=0
    flag=1
    cnt=0
    while rem>0 and j!=i:
        gain=0
        if flag:
            while gain<=prev and rem>0 and i!=j:
                i+=1
                gain+=arr[i]
                rem-=1
            flag=0
            alice+=gain
            prev=gain

        else:
            while gain<=prev and rem>0 and j!=i:
                j-=1
                gain+=arr[j]
                rem-=1
            flag=1
            bob+=gain
            prev=gain
        cnt+=1
    print(cnt,alice,bob,sep=" ")
    '''

#CF 641

'''test=int(input())
def f(n):
    i=2
    while i**2<=n:
        if n%i==0:
            return i
        i+=1
    return n


for i in range(test):
    n,k=[int(i) for i in input().split()]
    if n%2:
        n+=f(n)
        n+=2*(k-1)
    elif not n%2:
        n+=2*(k)
    print(n)'''

'''test=int(input())
for i in range(test):
    n=int(input())
    arr=[int(i) for i in input().split()]
    dp=[1]*(n)
    for i in range(len(arr)-1,-1,-1):
        flag=0
        intial=2
        mul=(i+1)*2
        while mul<=len(arr):
            if arr[mul-1]>arr[i]:
               dp[i]=max(dp[i],1+dp[mul-1])
            intial+=1
            mul=(i+1)*intial
    print(max(dp)) '''


#CF 642(DIV.-3)

test=int(input())
for i in range(test):
    n,m=[int(i) for i in input().split()]
    if n==1:
        print(0)
    elif n==2:
        print(m)
    else:
        print(2*m)
'''
test=int(input())
for i in range(test):
    n,k=[int(i) for i in input().split()]
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    if k==0:
        print(sum(a))
    else:
        a.sort()
        b.sort(reverse=True)
        for i in range(k):
            if a[i]<b[i]:
                a[i]=b[i]
        print(sum(a))'''

'''test=int(input())
for i in range(test):
    n=int(input())
    if n==3:
        print(8)
    elif n==1:
        print(0)    
    else:
        k=int((n-1)/2)
        expo=(k*(k+1)*(2*k+1))/3
        to=(k*(k+1))/2
        expo-=to
        ans=4*(expo+(k*(k+1))/2)
        print(int(ans))'''
