{"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\"\u003eMr. Frog learned a basic data structure recently, which is called stack.There are some basic operations of stack:\u003cbr\u003e\u003cbr\u003e$\\bullet $ PUSH x: put x on the top of the stack, x must be 0 or 1.\u003cbr\u003e$\\bullet $ POP: throw the element which is on the top of the stack.\u003cbr\u003e\u003cbr\u003eSince it is too simple for Mr. Frog, a famous mathematician who can prove \"Five points coexist with a circle\" easily, he comes up with some exciting operations:\u003cbr\u003e\u003cbr\u003e$\\bullet $REVERSE: Just reverse the stack, the bottom element becomes the top element of the stack, and the element just above the bottom element becomes the element just below the top elements... and so on.\u003cbr\u003e$\\bullet $QUERY: Print the value which is obtained with such way: Take the element from top to bottom, then do \u003cb\u003eNAND\u003c/b\u003e operation one by one from left to right, i.e. If\u0026nbsp;\u0026nbsp;$a_{top},a_{top-1},\\cdots , a_1$ is corresponding to the element of the Stack from top to the bottom, $value \u003d a_{top}$ nand $a_{top-1}$ nand ... nand $a_1$. Note that the Stack \u003cb\u003ewill not\u003c/b\u003e change after QUERY operation. Specially, if the Stack is empty now,you need to print ”\u003cb\u003eInvalid\u003c/b\u003e.”(without quotes).\u003cbr\u003e\u003cbr\u003eBy the way, \u003cb\u003eNAND\u003c/b\u003e is a basic binary operation:\u003cbr\u003e\u003cbr\u003e$\\bullet $ 0 nand 0 \u003d 1\u003cbr\u003e$\\bullet $ 0 nand 1 \u003d 1\u003cbr\u003e$\\bullet $ 1 nand 0 \u003d 1\u003cbr\u003e$\\bullet $ 1 nand 1 \u003d 0\u003cbr\u003e\u003cbr\u003eBecause Mr. Frog needs to do some tiny contributions now, you should help him finish this data structure: print the answer to each QUERY, or tell him that is invalid.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains only one integer T ($T \\leq 20$), which indicates the number of test cases.\u003cbr\u003e\u003cbr\u003eFor each test case, the first line contains only one integers N ($2 \\leq N \\leq 200000$), indicating the number of operations.\u003cbr\u003e\u003cbr\u003eIn the following N lines, the i-th line contains one of these operations below:\u003cbr\u003e\u003cbr\u003e$\\bullet $ PUSH x (x \u003cb\u003emust\u003c/b\u003e be 0 or 1)\u003cbr\u003e$\\bullet $ POP\u003cbr\u003e$\\bullet $ REVERSE\u003cbr\u003e$\\bullet $ QUERY\u003cbr\u003e\u003cbr\u003eIt is guaranteed that the current stack will not be empty while doing POP operation.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, first output one line \"Case #x:w, where x is the case number (starting from 1). Then several lines follow,\u0026nbsp;\u0026nbsp;i-th line contains an integer indicating the answer to the i-th QUERY operation. Specially, if the i-th QUERY is invalid, just print \"\u003cb\u003eInvalid.\u003c/b\u003e\"(without quotes). (Please see the sample for more details.)\u003cbr\u003e"}},{"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\u003e2\r\n8\r\nPUSH 1\r\nQUERY\r\nPUSH 0\r\nREVERSE\r\nQUERY\r\nPOP\r\nPOP\r\nQUERY\r\n3\r\nPUSH 0\r\nREVERSE\r\nQUERY\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1:\r\n1\r\n1\r\nInvalid.\r\nCase #2:\r\n0\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":"\u003cbr\u003eIn the first sample: during the first query, the stack contains only one element 1, so the answer is 1. then in the second query, the stack contains 0, l\u003cbr\u003e(from bottom to top), so the answer to the second is also 1. In the third query, there is no element in the stack, so you should output Invalid. \u003cbr\u003e"}}]}