{"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\"\u003eAs everyone knows, DRD has no girlfriends. But as everyone also knows, DRD’s friend ATM’s friend CLJ has many potential girlfriends. One evidence is CLJ’s chatting record.\u003cbr\u003e\u003cbr\u003e\u003ccenter\u003e\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/11cc83fdd4adf94fc035c25b1e24af2f?v\u003d1724975766\"\u003e\u003c/center\u003e\u003cbr\u003eCLJ chats with many girls all the time. Sometimes he begins a new conversation and sometimes he ends a conversation. Sometimes he chats with the girl whose window is on the top.\u003cbr\u003e\u003cbr\u003eYou can imagine CLJ’s windows as a queue. The first girl in the queue is the top girl if no one is “always on top ”.\u003cbr\u003e\u003cbr\u003eSince CLJ is so popular, he begins to assign a unique positive integer as priority for every girl. The higher priority a girl has, the more CLJ likes her. For example, GYZ has priority 10\u003csup\u003e9\u003c/sup\u003e, and JZP has priority 10\u003csup\u003e8\u003c/sup\u003e while Sister Soup has priority 1, and Face Face has priority 2.\u003cbr\u003e\u003cbr\u003eAs a famous programmer, CLJ leads a group to implement his own WM(window manager). The WM will log CLJ’s operations. Now you are supposed to implement the log system. The general logging format is “Operation #X: LOGMSG.”, where X is the number of the operation and LOGMSG is the logging message.\u003cbr\u003e\u003cbr\u003eThere are several kinds of operations CLJ may use:\u003cbr\u003e\u003cbr\u003e 1.\u003cb\u003eAdd u:\u003c/b\u003e CLJ opens a new window whose priority is u, and the new window will be the last window in the window queue. This operation will always be successful except the only case in which there is already a window with priority u. If it is successful, LOGMSG will be “success”. Otherwise LOGMSG will be “same priority”.\u003cbr\u003e\u003cbr\u003e 2.\u003cb\u003eClose u:\u003c/b\u003e CLJ closes a window whose priority is u. If there exists such a window, the operation will be successful and LOGMSG will be “close u with c”, where u is the priority and c is the number of words CLJ has spoken to this window. Otherwise, LOGMSG will be “invalid priority”. Note that ANY window can be closed.\u003cbr\u003e\u003cbr\u003e 3.\u003cb\u003eChat w:\u003c/b\u003e CLJ chats with the top window, and he speaks w words. The top window is the first window in the queue, or the “always on top” window (as described below) instead if there exists. If no window is in the queue, LOGMSG will be “empty”, otherwise the operation can be successful and LOGMSG will be “success”.\u003cbr\u003e\u003cbr\u003e 4.\u003cb\u003eRotate x:\u003c/b\u003e CLJ performs one or more Alt-Tabs to move the x-th window to the first one in the queue. For example, if there are 4 windows in the queue, whose priorities are 1, 3, 5, 7 respectively and CLJ performs “Rotate 3”, then the window’s priorities in the queue will become 5, 1, 3, 7. Note that if CLJ wants to move the first window to the head, this operation is still considered “successful”. If x is out of range (smaller than 1 or larger than the size of the queue), LOGMSG will be “out of range”. Otherwise LOGMSG should be “success”.\u003cbr\u003e\u003cbr\u003e 5.\u003cb\u003ePrior:\u003c/b\u003e CLJ finds out the girl with the maximum priority and then moves the window to the head of the queue. Note that if the girl with the maximum priority is already the first window, this operation is considered successful as well. If the window queue is empty, this operation will fail and LOGMSG must be “empty”. If it is successful, LOGMSG must be “success”.\u003cbr\u003e\u003cbr\u003e 6.\u003cb\u003eChoose u:\u003c/b\u003e CLJ chooses the girl with priority u and moves the window to the head of the queue.This operation is considered successful if and only if the window with priority u exists. LOGMSG for the successful cases should be “success” and for the other cases should be “invalid priority”.\u003cbr\u003e\u003cbr\u003e 7.\u003cb\u003eTop u:\u003c/b\u003e CLJ makes the window of the girl with priority u always on top. Always on top is a special state, which means whoever the first girl in the queue is, the top one must be u if u is always on top. As you can see, two girls cannot be always on top at the same time, so if one girl is always on top while CLJ wants another always on top, the first will be not always on top any more, except the two girls are the same one. Anyone can be always on top. LOGMSG is the same as that of the Choose operation.\u003cbr\u003e\u003cbr\u003e 8.\u003cb\u003eUntop:\u003c/b\u003e CLJ cancels the “always on top” state of the girl who is always on top. That is, the girl who is always on top now is not in this special state any more. This operation will fail unless there is one girl always on top. If it fails, LOGMSG should be “no such person”, otherwise should be “success”.\u003cbr\u003e\u003cbr\u003eAs a gentleman, CLJ will say goodbye to every active window he has ever spoken to at last, “active” here means the window has not been closed so far. The logging format is “Bye u: c” where u is the priority and c is the number of words he has ever spoken to this window. He will always say good bye to the current top girl if he has spoken to her before he closes it.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains an integer T (T ≤ 10), denoting the number of the test cases.\u003cbr\u003e\u003cbr\u003eFor each test case, the first line contains an integer n(0 \u0026lt; n ≤ 5000), representing the number of operations. Then follow n operations, one in a line. All the parameters are positive integers below 10\u003csup\u003e9\u003c/sup\u003e."}},{"title":"Output","value":{"format":"HTML","content":"Output all the logging contents."}},{"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\n18\r\nPrior\r\nAdd 1\r\nChat 1\r\nAdd 2\r\nChat 2\r\nTop 2\r\nChat 3\r\nUntop\r\nChat 4\r\nChoose 2\r\nChat 5\r\nRotate 2\r\nChat 4\r\nClose 2\r\nAdd 3\r\nPrior\r\nChat 2\r\nClose 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eOperation #1: empty.\r\nOperation #2: success.\r\nOperation #3: success.\r\nOperation #4: success.\r\nOperation #5: success.\r\nOperation #6: success.\r\nOperation #7: success.\r\nOperation #8: success.\r\nOperation #9: success.\r\nOperation #10: success.\r\nOperation #11: success.\r\nOperation #12: success.\r\nOperation #13: success.\r\nOperation #14: close 2 with 8.\r\nOperation #15: success.\r\nOperation #16: success.\r\nOperation #17: success.\r\nOperation #18: close 1 with 11.\r\nBye 3: 2\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"This problem description does not relate to any real person in THU."}}]}