{"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\"\u003ePonyo and Garfield are waiting outside the box-office for their favorite movie. Because queuing is so boring, that they want to play a game to kill the time. The game is called “Queue-jumpers”. Suppose that there are N people numbered from 1 to N stand in a line initially. Each time you should simulate one of the following operations:\u003cbr\u003e1.\u0026nbsp;\u0026nbsp;Top x :Take person x to the front of the queue\u003cbr\u003e2.\u0026nbsp;\u0026nbsp;Query x: calculate the current position of person x\u003cbr\u003e3.\u0026nbsp;\u0026nbsp;Rank x: calculate the current person at position x\u003cbr\u003eWhere x is in [1, N].\u003cbr\u003ePonyo is so clever that she plays the game very well while Garfield has no idea. Garfield is now turning to you for help.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"In the first line there is an integer T, indicates the number of test cases.(T\u0026lt;\u003d50)\u003cbr\u003eIn each case, the first line contains two integers N(1\u0026lt;\u003dN\u0026lt;\u003d10^8), Q(1\u0026lt;\u003dQ\u0026lt;\u003d10^5). Then there are Q lines, each line contain an operation as said above. \u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, output “Case d:“ at first line where d is the case number counted from one, then for each “Query x” operation ,output the current position of person x at a line, for each “Rank x” operation, output the current person at position x at a line."}},{"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\u003e3\r\n9 5\r\nTop 1\r\nRank 3\r\nTop 7\r\nRank 6\r\nRank 8\r\n6 2\r\nTop 4\r\nTop 5\r\n7 4\r\nTop 5\r\nTop 2\r\nQuery 1\r\nRank 6\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\r\n3\r\n5\r\n8\r\nCase 2:\r\nCase 3:\r\n3\r\n6\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}