{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eYou may heard of the Joseph Problem, the story comes from a Jewish historian living in 1st century. He and his 40 comrade soldiers were trapped in a cave, the exit of which was blocked by Romans. They chose suicide over capture and decided that they would form a circle and start killing themselves using a step of three. Josephus states that by luck or maybe by the hand of God, he and another man remained the last and gave up to the Romans.\u003cbr\u003e\u003cbr\u003eNow the problem is much easier: we have N men stand in a line and labeled from 1 to N, for each round, we choose the first man, the k+1-th one, the 2*k+1-th one and so on, until the end of the line. These poor guys will be kicked out of the line and we will execute them immediately (may be head chop, or just shoot them, whatever), and then we start the next round with the remaining guys. The little difference between the Romans and us is, in our version of story, NO ONE SURVIVES. Your goal is to find out the death sequence of the man.\u003cbr\u003e\u003cbr\u003eFor example, we have N \u003d 7 prisoners, and we decided to kill every k\u003d2 people in the line. At the beginning, the line looks like this:\u003cbr\u003e\u003cbr\u003e1 2 3 4 5 6 7\u003cbr\u003e\u003cbr\u003eafter the first round, 1 3 5 7 will be executed, we have\u003cbr\u003e\u003cbr\u003e2 4 6\u003cbr\u003e\u003cbr\u003eand then, we will kill 2 6 in the second round. At last 4 will be executed. So, you need to output 1 3 5 7 2 6 4. Easy, right?\u003cbr\u003e\u003cbr\u003eBut the output maybe too large, we will give you Q queries, each one contains a number m, you need to tell me the m-th number in the death sequence.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"Multiple cases. The first line contains a number T, means the number of test case. For every case, there will be three integers N (1\u0026lt;\u003dN\u0026lt;\u003d3000000), K(1\u0026lt;\u003dK), and Q(1\u0026lt;\u003dQ\u0026lt;\u003d1000000), which indicate the number of prisoners, the step length of killing, and the number of query. Next Q lines, each line contains one number m(1\u0026lt;\u003dm\u0026lt;\u003dn)."}},{"title":"Output","value":{"format":"HTML","content":"For each query m, output the m-th number in the death sequence."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n7 2 7\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n3\r\n5\r\n7\r\n2\r\n6\r\n4\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}