N knights were sitting at a round table and having a serious talk. The knights are so tired, that they can’t even rotate their neck to talk to talk to the knights sitting on their sides. So, a knight can only talk to the knight sitting diametrically opposite to him on the table.
Given the number of knights N, find the index of the knight sitting opposite to the knight numbered M. It is ensured that there is always a knight in front of the knight numbered M. Knights are indexed in clockwise manner from 1 to N.
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space separated integers N and M denoting the number of knights and the index of knight for which answer is required.
For each test case, output a single integer containing the required answer to the problem.
1 ≤ T ≤ 100000
1 ≤ N ≤ 1018
1 ≤ M ≤ N
Input: 1 6 2 Output: 5
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions