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=int(raw_input())
i=0
while i<t:
	s=raw_input()
	m,n=map(int,s.split())
	l=[]
	m=m-1
	l.append(m)
	c=0
	j=0
	q=m
	while j<m:
		if j%2==0:
			l.append(c)
			c=c+1
		else:
			q=q-1
			l.append(q)
		j=j+1
	i=i+1
	w=l.index(n)
	print w