{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eAs an ACM-ICPC newbie, Aishah is learning data structures in computer science. She has already known that a stack, as a data structure, can serve as a collection of elements with two operations:\u003c/p\u003e\u003cul\u003e \u003cli\u003e push, which inserts an element to the collection, and \u003c/li\u003e\u003cli\u003e pop, which deletes the most recently inserted element that has not yet deleted. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eNow, Aishah hopes a more intelligent stack which can display the maximum element in the stack dynamically. Please write a program to help her accomplish this goal and go through a test with several operations.\u003c/p\u003e\u003cp\u003eAishah assumes that the stack is empty at first. Your program will output the maximum element in the stack after each operation. If at some point the stack is empty, the output should be zero.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe input contains several test cases, and the first line is a positive integer $$$T$$$ indicating the number of test cases which is up to $$$50$$$.\u003c/p\u003e\u003cp\u003eTo avoid unconcerned time consuming in reading data, each test case is described by seven integers $$$n~(1\\le n\\le 5 \\times 10^6)$$$, $$$p$$$, $$$q$$$, $$$m~(1\\le p, q, m\\le 10^9)$$$, $$$SA$$$, $$$SB$$$ and $$$SC~(10^4 \\le SA, SB, SC\\le 10^6)$$$. The integer $$$n$$$ is the number of operations, and your program is asked to generate all operations by using the following code in C\u003cspan class\u003d\"tex-font-style-tt\"\u003e++\u003c/span\u003e.\u003c/p\u003e\u003cp\u003e\u003cspan class\u003d\"tex-font-style-tt\"\u003e\nint n, p, q, m; \nunsigned int SA, SB, SC; \nunsigned int rng61(){ SA ^\u003d SA \u003c\u003c16; SA ^\u003d SA \u003e\u003e 5; SA ^\u003d SA \u003c\u003c 1; \nunsigned int t \u003d SA; SA \u003d SB; SB \u003d SC; SC ^\u003d t ^ SA; return SC; } \nvoid gen()\n{\n \n scanf(\"%lld%lld%lld%lld%u%u%u\",\u0026n,\u0026p,\u0026q,\u0026m,\u0026SA,\u0026SB,\u0026SC);\n for(int i\u003d1;i\u003c\u003dn;i++)\n {\n if(rng61()%(p+q) \u003c p) PUSH(rng61()%m+1);\n else POP();\n }\n}\n\u003c/span\u003e\u003c/p\u003e\u003cp\u003eThe procedure \u003cspan class\u003d\"tex-font-style-tt\"\u003ePUSH(v)\u003c/span\u003e used in the code inserts a new element with value $$$v$$$ into the stack and the procedure \u003cspan class\u003d\"tex-font-style-tt\"\u003ePOP()\u003c/span\u003e pops the topmost element in the stack or does nothing if the stack is empty.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case, output a line containing \u003cspan class\u003d\"tex-font-style-tt\"\u003eCase #x: y\u003c/span\u003e, where \u003cspan class\u003d\"tex-font-style-tt\"\u003ex\u003c/span\u003e is the test case number starting from $$$1$$$, and \u003cspan class\u003d\"tex-font-style-tt\"\u003ey\u003c/span\u003e is equal to $$$\\mathop{\\oplus}\\limits_{i \u003d 1}^{n}{\\left(i \\cdot a_i\\right)}$$$ where $$$\\oplus$$$ means bitwise xor. $$$a_i$$$ is the answer after the i-th operation.\u003c/p\u003e"}},{"title":"Examples","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\n4 1 1 4 23333 66666 233333\n4 2 1 4 23333 66666 233333\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1: 19\nCase #2: 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eThe first test case in the sample input has $$$4$$$ operations: \u003c/p\u003e\u003cul\u003e \u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ePOP()\u003c/span\u003e; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ePOP()\u003c/span\u003e; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ePUSH(1)\u003c/span\u003e; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ePUSH(4)\u003c/span\u003e. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eThe second test case also has $$$4$$$ operations: \u003c/p\u003e\u003cul\u003e \u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ePUSH(2)\u003c/span\u003e; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ePOP()\u003c/span\u003e; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ePUSH(1)\u003c/span\u003e; \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ePOP()\u003c/span\u003e. \u003c/li\u003e\u003c/ul\u003e"}}]}