<h1 style="color: rgb(26, 92, 200); text-align: center; font-family: 'Times New Roman';">Doom</h1><span style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;"><strong><span style="font-family: Arial; font-size: 12px; color: green;">Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 806 Accepted Submission(s): 200
</span></strong></span><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Problem Description</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">THE END IS COMINGGGGGG!
Mike has got stuck on a mystery machine. If he cannot solve this problem, he will go to his doom.
This machine is consist of <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-1-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-1" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.697em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.628em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-2" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-3" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">n</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.646em;"></span></span></nobr></span> cells, and a screen. The <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-2-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-4" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.35em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.35em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.529em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-5" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-6" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">i</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.861em;"></span></span></nobr></span>-th cell contains a number <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-3-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-7" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 6.106em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 5.898em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.737em 1000.003em 3.193em -0.621em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-8" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="msubsup" id="MathJax-Span-9" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.974em; height: 0px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mi" id="MathJax-Span-10" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">a</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; top: -2.146em; left: 0.558em;"><span class="mi" id="MathJax-Span-11" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-size: 12px; font-family: MathJax_Math-italic;">i</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.292em;"></span></span></span></span><span class="mo" id="MathJax-Span-12" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">(</span><span class="mn" id="MathJax-Span-13" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-14" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="mi" id="MathJax-Span-15" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">i</span><span class="mo" id="MathJax-Span-16" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="mi" id="MathJax-Span-17" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">n</span><span class="mo" id="MathJax-Span-18" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">)</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.354em; overflow: hidden; width: 0px; height: 1.146em;"></span></span></nobr></span>. The screen also contains a number <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-4-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-19" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.489em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.489em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.551em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-20" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-21" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">s</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.646em;"></span></span></nobr></span>, which is initially <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-5-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-22" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.558em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.558em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.916em -0.551em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-23" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mn" id="MathJax-Span-24" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">0</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.861em;"></span></span></nobr></span>.
There is a button on each cell. When the <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-6-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-25" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.35em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.35em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.529em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-26" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-27" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">i</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.861em;"></span></span></nobr></span>-th is pushed, Mike observes that, the number on the screen will be changed to <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-7-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-28" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 2.777em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 2.708em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.945em 1000.003em 3.055em -0.551em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-29" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-30" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">s</span><span class="mo" id="MathJax-Span-31" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.212em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">+</span><span class="msubsup" id="MathJax-Span-32" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.212em; margin: 0px; vertical-align: 0px;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.974em; height: 0px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mi" id="MathJax-Span-33" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">a</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; top: -2.146em; left: 0.558em;"><span class="mi" id="MathJax-Span-34" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-size: 12px; font-family: MathJax_Math-italic;">i</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.292em;"></span></span></span></span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.211em; overflow: hidden; width: 0px; height: 0.932em;"></span></span></nobr></span>, where <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-8-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-35" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.489em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.489em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.551em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-36" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-37" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">s</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.646em;"></span></span></nobr></span> is the original number. and the number on the <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-9-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-38" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.35em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.35em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.529em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-39" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-40" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">i</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.861em;"></span></span></nobr></span>-th cell will be changed to <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-10-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-41" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 1.182em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 1.113em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(-0.066em 1000.003em 1.46em -0.621em); top: -0.967em; left: 0.003em;"><span class="mrow" id="MathJax-Span-42" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="msubsup" id="MathJax-Span-43" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 1.044em; height: 0px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mi" id="MathJax-Span-44" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">a</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.737em 1000.003em 2.639em -0.551em); top: -2.77em; left: 0.558em;"><span class="mn" id="MathJax-Span-45" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-size: 12px; font-family: MathJax_Main;">2</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.598em 1000.003em 2.5em -0.621em); top: -2.008em; left: 0.558em;"><span class="mi" id="MathJax-Span-46" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-size: 12px; font-family: MathJax_Math-italic;">i</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.292em;"></span></span></span></span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 0.974em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.354em; overflow: hidden; width: 0px; height: 1.289em;"></span></span></nobr></span>.
Mike observes that the number is stored in radix <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-11-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-47" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.558em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.558em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.847em -0.69em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-48" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-49" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">p</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.282em; overflow: hidden; width: 0px; height: 0.789em;"></span></span></nobr></span>, where <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-12-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-50" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 11.723em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 11.377em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 3.124em -0.69em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-51" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-52" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">p</span><span class="mo" id="MathJax-Span-53" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">=</span><span class="mn" id="MathJax-Span-54" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">9223372034707292160</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.282em; overflow: hidden; width: 0px; height: 1.075em;"></span></span></nobr></span>. In other words , the operation is under modulo <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-13-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-55" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.558em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.558em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.847em -0.69em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-56" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-57" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">p</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.282em; overflow: hidden; width: 0px; height: 0.789em;"></span></span></nobr></span>.
And now, Mike has got a list of operations. One operation is to push buttons between from <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-14-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-58" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.35em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.35em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.529em 1000.003em 2.639em -0.551em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-59" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-60" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">l</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.861em;"></span></span></nobr></span>-th to <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-15-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-61" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.489em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.489em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-62" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-63" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">r</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.646em;"></span></span></nobr></span>-th (both included), and record the number on the screen. He is tired of this stupid work, so he asks for your help. Can you tell him, what are the numbers recorded.
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Input</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">The first line contains an integer <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-16-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-64" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.836em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.766em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.529em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-65" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-66" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">T<span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; overflow: hidden; height: 1px; width: 0.142em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.861em;"></span></span></nobr></span>(<span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-17-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-67" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 2.639em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 2.569em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 3.055em -0.621em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-68" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-69" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">T<span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; overflow: hidden; height: 1px; width: 0.142em;"></span></span><span class="mo" id="MathJax-Span-70" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="mn" id="MathJax-Span-71" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">5</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.211em; overflow: hidden; width: 0px; height: 1.004em;"></span></span></nobr></span>), denoting the number of test cases.
For each test case, the first line contains two integers <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-18-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-72" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 2.015em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 1.945em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(2.084em 1000.003em 3.124em -0.621em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-73" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-74" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">n</span><span class="mo" id="MathJax-Span-75" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">,</span><span class="mi" id="MathJax-Span-76" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.142em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">m</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.282em; overflow: hidden; width: 0px; height: 0.789em;"></span></span></nobr></span>(<span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-19-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-77" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 6.869em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 6.661em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.668em 1000.003em 3.124em -0.551em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-78" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mn" id="MathJax-Span-79" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-80" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="mi" id="MathJax-Span-81" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">n</span><span class="mo" id="MathJax-Span-82" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">,</span><span class="mi" id="MathJax-Span-83" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.142em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">m</span><span class="mo" id="MathJax-Span-84" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="msubsup" id="MathJax-Span-85" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 1.529em; height: 0px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.916em -0.551em); top: -2.701em; left: 0.003em;"><span class="mn" id="MathJax-Span-86" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">10</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; top: -2.84em; left: 1.044em;"><span class="mn" id="MathJax-Span-87" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-size: 12px; font-family: MathJax_Main;">5</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span></span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.282em; overflow: hidden; width: 0px; height: 1.218em;"></span></span></nobr></span>).
The next line contains <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-20-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-88" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.697em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.628em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-89" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-90" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">n</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.646em;"></span></span></nobr></span> integers <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-21-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-91" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 1.113em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 1.044em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(0.35em 1000.003em 1.321em -0.621em); top: -0.967em; left: 0.003em;"><span class="mrow" id="MathJax-Span-92" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="msubsup" id="MathJax-Span-93" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.974em; height: 0px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mi" id="MathJax-Span-94" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">a</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; top: -2.146em; left: 0.558em;"><span class="mi" id="MathJax-Span-95" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-size: 12px; font-family: MathJax_Math-italic;">i</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.292em;"></span></span></span></span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 0.974em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.211em; overflow: hidden; width: 0px; height: 0.789em;"></span></span></nobr></span>(<span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-22-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-96" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 4.788em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 4.65em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 3.124em -0.551em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-97" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mn" id="MathJax-Span-98" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">0</span><span class="mo" id="MathJax-Span-99" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="msubsup" id="MathJax-Span-100" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.974em; height: 0px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mi" id="MathJax-Span-101" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">a</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; top: -2.146em; left: 0.558em;"><span class="mi" id="MathJax-Span-102" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-size: 12px; font-family: MathJax_Math-italic;">i</span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.292em;"></span></span></span></span><span class="mo" id="MathJax-Span-103" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;"><</span><span class="mi" id="MathJax-Span-104" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">p</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.282em; overflow: hidden; width: 0px; height: 1.004em;"></span></span></nobr></span>), which means the initial values of the <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-23-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-105" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.697em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.628em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-106" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-107" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">n</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.646em;"></span></span></nobr></span> cells.
The next <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-24-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-108" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.974em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.905em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.807em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-109" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-110" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">m</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.646em;"></span></span></nobr></span> lines describe operations. In each line, there are two integers <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-25-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-111" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 8.117em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 7.84em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.737em 1000.003em 3.193em -0.551em); top: -2.701em; left: 0.003em;"><span class="mrow" id="MathJax-Span-112" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-113" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">l</span><span class="mo" id="MathJax-Span-114" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">,</span><span class="mi" id="MathJax-Span-115" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.142em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">r</span><span class="mo" id="MathJax-Span-116" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">(</span><span class="mn" id="MathJax-Span-117" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">1</span><span class="mo" id="MathJax-Span-118" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="mi" id="MathJax-Span-119" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">l</span><span class="mo" id="MathJax-Span-120" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="mi" id="MathJax-Span-121" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">r</span><span class="mo" id="MathJax-Span-122" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">≤</span><span class="mi" id="MathJax-Span-123" style="transition: none; display: inline; position: static; border: 0px; padding: 0px 0px 0px 0.281em; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">n</span><span class="mo" id="MathJax-Span-124" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Main;">)</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.708em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.354em; overflow: hidden; width: 0px; height: 1.146em;"></span></span></nobr></span>, representing the operation.
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Output</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">For each test case, output ''Case #t:'', to represent this is the <span class="MathJax_Preview" style="color: rgb(136, 136, 136);"></span><span class="MathJax" id="MathJax-Element-26-Frame" role="textbox" aria-readonly="true" style="display: inline; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px;"><nobr style="transition: none; border: 0px; padding: 0px; margin: 0px; max-width: none; max-height: none; min-width: 0px; min-height: 0px; vertical-align: 0px;"><span class="math" id="MathJax-Span-125" style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.42em;"><span style="transition: none; display: inline-block; position: relative; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0.42em; height: 0px; font-size: 14.4200000762939px;"><span style="transition: none; position: absolute; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; clip: rect(1.598em 1000.003em 2.639em -0.621em); top: -2.424em; left: 0.003em;"><span class="mrow" id="MathJax-Span-126" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px;"><span class="mi" id="MathJax-Span-127" style="transition: none; display: inline; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; font-family: MathJax_Math-italic;">t</span></span><span style="transition: none; display: inline-block; position: static; border: 0px; padding: 0px; margin: 0px; vertical-align: 0px; width: 0px; height: 2.431em;"></span></span></span><span style="transition: none; display: inline-block; position: static; border-width: 0px 0px 0px 0.004em; border-left-style: solid; border-color: initial; padding: 0px; margin: 0px; vertical-align: -0.068em; overflow: hidden; width: 0px; height: 0.789em;"></span></span></nobr></span>-th case. And then output the answer for each query operation, one answer in a line.
For more details you can take a look at the example.
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Sample Input</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;"><pre style="word-wrap: break-word; white-space: pre-wrap; margin-top: 0px; margin-bottom: 0px;"><div style="font-family: 'Courier New', Courier, monospace;">2
4 4
2 3 4 5
1 2
2 3
3 4
1 4
1 3
2
1 1
1 1
1 1</div>
Sample Output
Case #1: 5 18 39 405 Case #2: 2 6 22
一个数平方超过30次过后 mod 题目给的这个特殊数 不会变了 用个线段树维护区间内被更新的最小个数
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 100005
typedef unsigned long long ll;
ll a[N];
ll mmm = 9223372034707292160ll;
struct Tree{
int l, r;
int cnt;
ll sum;
}tree[N<<2];
ll quick_chen(ll a,ll b){
ll ans = 0;
while(b){
if(b & 1) {
ans = (ans + a ) % mmm;
}
b >>= 1;
a = (a + a) % mmm;
}
return ans;
}
void pushup(int root){//儿子把信息传递给父亲
if(tree[root].l==tree[root].r)return ;
tree[root].sum=(tree[root<<1].sum+tree[root<<1|1].sum)%mmm; //<<1:*2; <<1|1:*2+1
tree[root].cnt=min(tree[root<<1].cnt,tree[root<<1|1].cnt);
return ;
}
void build(int l,int r,int root){
tree[root].l=l;
tree[root].r=r;
tree[root].sum = 0;
tree[root].cnt = 0;
if(l==r){//直到单个区间位置
tree[root].sum = a[l];
return;
}
int mid=(l+r)>>1;
build(l,mid,root<<1);//左区间
build(mid+1,r,root<<1|1); //右区间
pushup(root);//把儿子的信息更新到父亲
return;
}
void update(int l,int r,int root){
if(tree[root].cnt>=29) return;
if(tree[root].l==tree[root].r){
tree[root].sum= quick_chen(tree[root].sum ,tree[root].sum)%mmm;
tree[root].cnt++;
return ;
}
int mid=tree[root].l+tree[root].r>>1;
if(r<=mid)update(l,r,root<<1);
else if(l>mid)update(l,r,root<<1|1);
else {
update(l,mid,root<<1);
update(mid+1,r,root<<1|1);
}
pushup(root);//更新父亲
return ;
}
__int64 query(int l,int r,int root){
if(l==tree[root].l&&tree[root].r==r){
return tree[root].sum;
}
int mid=tree[root].l+tree[root].r>>1;
if(r<=mid)return query(l,r,root<<1);
else if(l>mid)return query(l,r,root<<1|1);
else return (query(l,mid,root<<1) + query(mid+1,r,root<<1|1)) % mmm;
}
int main()
{
int t;
scanf("%d", &t);
//printf("%I64\d",mmm);
for(int cas = 1;cas <= t;cas++)
{
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1;i <= n;i++){
scanf("%I64u", a+i);
}
build(1,n,1);
ll ans = 0;
printf("Case #%d:\n",cas);
while(m--)
{
int l, r;
scanf("%d%d", &l, &r);
ans = (ans + query(l,r,1)) % mmm;
printf("%I64u\n", ans);
update(l,r,1);
}
}
}