{"problem":{"name":"Long Shuffle","description":{"content":"There is an array $A_1, \\ldots, A_N$, and initially $A_i = i$ for all $i$. Define the following routine $\\mathrm{shuffle}(L, R)$: *   If $R = L + 1$, swap values of $A_L$ and $A_R$ and terminate. *  ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc061_a"},"statements":[{"statement_type":"Markdown","content":"There is an array $A_1, \\ldots, A_N$, and initially $A_i = i$ for all $i$. Define the following routine $\\mathrm{shuffle}(L, R)$:\n\n*   If $R = L + 1$, swap values of $A_L$ and $A_R$ and terminate.\n*   Otherwise, run $\\mathrm{shuffle}(L, R - 1)$ followed by $\\mathrm{shuffle}(L + 1, R)$.\n\nSuppose we run $\\mathrm{shuffle}(1, N)$. Print the value of $A_K$ after the routine finishes.\nFor each input file, solve $T$ test cases.\n\n## Constraints\n\n*   $1 \\leq T \\leq 1000$\n*   $2 \\leq N \\leq 10^{18}$\n*   $1 \\leq K \\leq N$\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$T$\n$case_1$\n$case_2$\n$\\vdots$\n$case_T$\n\nEach case is in the following format:\n\n$N$ $K$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc061_a","tags":[],"sample_group":[["7\n2 1\n2 2\n5 1\n5 2\n5 3\n5 4\n5 5","2\n1\n2\n4\n1\n5\n3\n\nFor $N=2$, we do the following and get $A=(2,1)$.\n\n*   Run $\\mathrm{shuffle}(1, 2)$, and swap $A_1$ and $A_2$.\n\nFor $N=5$, we do the following and get $A=(2,4,1,5,3)$.\n\n*   Run $\\mathrm{shuffle}(1, 5)$:\n    *   Run $\\mathrm{shuffle}(1, 4)$:\n        *   Run $\\mathrm{shuffle}(1, 3)$:\n            *   $\\vdots$\n        *   Run $\\mathrm{shuffle}(2, 4)$:\n            *   $\\vdots$\n    *   Run $\\mathrm{shuffle}(2, 5)$:\n        *   Run $\\mathrm{shuffle}(2, 4)$:\n            *   $\\vdots$\n        *   Run $\\mathrm{shuffle}(3, 5)$:\n            *   $\\vdots$"]],"created_at":"2026-03-03 11:01:14"}}