Problem: Joy and Rock decided to play a game. They have N cards numbered from 0 to N−1. Joy asks Rock to reverse the position of the cards, i.e., to change the order from say, 0,1,2,3 to 3,2,1,0. He further asks Rock to reverse the position of the cards N times, each time starting from one position further to the right, till he reaches the last card. So, Rock has to reverse the positions of the cards starting from initial position i.e., 0th, then from 1st ,then from 2nd and so on. At the end of the game, Joy will ask Rock the final position of any card numbered M. Help Rock to find out the answer.

Input Format:

The first line contains an integer T, i.e., the number of the test cases. 
The next T lines will contain two integers N and M.

Output Format:

Print the final index in array.

Constraints:

1≤T≤80

1≤N≤ 10 ^ 8 

0≤M<N

SAMPLE INPUT
2
4 1 
6 3

SAMPLE OUTPUT
3
4

Explanation

For first test case:

0\; 1\; 2\; 3\; -> 3\; 2\; 1\; 0\; -> 3\; 0\; \;1\; 2\; -> 3\; 0\; 2\; 1\;

So, 1 is at index 3.

For second test case:

0\; 1\; 2\; 3\; 4\; 5\; -> 5\; 4\; 3\; 2\; 1\; 0\; -> 5\; 0\; 1\; 2\; 3\; 4\; -> 5\; 0\; 4\; 3\; 2\; 1\; -> 5\; 0\; 4\; 1\; 2\; 3\; -> 5\; 0\; 4\; 1\; 3\; 2\; 

So, 3 is at index 4.

Solution (in PYTHON):

Solution:
t=input()
l=0
while l<t:
	n=raw_input()
	n=n.split()
	m=int(n[1])
	n=int(n[0])
	a=[]
	for i in range(n):
		a.append(i)
	j=len(a)-1
	b=[]
	for i in range(len(a)):
		if i>j:
			break
		else:
			b.append(a[j])
			b.append(a[i])
			j=j-1
	for i in range(len(b)):
		if b[i]==m:
			print i
			break
	l=l+1