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
'''
#print 'Hello World!'
n = 0
while n == 0:
	n = int(raw_input())
	
i = 0
while i < n:
	tc = []
	while (len(tc) == 0):
		tc = map(int,raw_input().split())
		
	a = []
	j = 0
	while j < tc[0]:
		a.append(j)
		j += 1
	aa = []
	a = a[::-1]
	k = 0
	
	while k < len(a)/2:
		aa.append(a[k])
		aa.append(a[len(a)-k-1])
		k += 1
	
	if len(a) % 2 == 1:
		aa.append(a[len(a)/2])
	
	#print a
	#print aa
	print aa.index(tc[1])
	a = []
	i += 1