game-10
Source: hackerearth
Difficulty: EASY

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.


t=eval(input())
l=0
while l<t:
	n=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


'''
# 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(input())
	
i = 0
while i < n:
	tc = []
	while (len(tc) == 0):
		tc = list(map(int,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


t=int(input())
i=0
while i<t:
	s=input()
	m,n=list(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)


import sys

for __ in range(eval(input())) :
	a , b = list(map(int,sys.stdin.readline().split()))
	if b < (a/2) :
		print(((b*2)+2)-1)
	else :
		print(((a-1)-b) * 2)