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:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=input()
for _ in range(t):
	b=[]
	x=[]
	y=[]
	n,m=map(int,raw_input().split())
	if((n-1)%2):
		p=int(((n-1)/2)+1)
	else :
		p=(n-1)/2
	for i in range(0,p):
		b.append(n-i-1)
		b.append(i)
	if((n)%2):
		b.append(n/2)
	print b.index(m)