|
Izumi |
So, who won that watermelon-shooting contest earlier? |
|
Hifumi |
...Huh? Y-you're the one who interrupted it, Izumi! And please don't bring that up again! |
|
Azusa |
True... We never did settle it. |
|
Mashiro |
Indeed. You've pointed out something we nearly overlooked. Letting it end so inconclusively would disgrace the Justice Task Force! |
|
Azusa |
Agreed. Withdrawing from the battlefield without a clear outcome would tarnish the name of the Make-Up Work Club. |
|
Hifumi |
Azusa-chan?! I don't think the Make-Up Work Club's name carries quite that much weight! |
Arrangement of the coconuts
First, there are coconuts arranged in a circle around the firing position. It seems is even. The coconuts are evenly spaced. Let one of them be coconut , then number the others , , …, in counterclockwise order from it.
The program Sensei uses defines two imaginary straight axes, and .
The first line contains the number of coconuts , the number of subqueries , the number of queries , and the initially selected coconut number , separated by spaces. (, is even; ; ; )
Print the coconut numbers Sensei will call out, in order, one per line.
The figure below shows the selected coconut and all subqueries before processing any queries and after each of the five queries is processed in order.
We can see that Sensei will call out number 5.
|
Azusa |
Hmm. Even if we wanted a rematch, the watermelons are no longer usable... |
|
Mashiro |
Then let's settle this with something other than watermelons! How about the fruit on those palm trees, for example?! |
|
Azusa |
Good. We can use those to finish our match. |
|
Mashiro |
Sensei can use a program to call out the fruit numbers, and we'll compete to hit them. |
|
Azusa |
We're counting on you, Sensei. |
I should do my best to live up to Hifumi-chan's expectations. ...Let's go over the situation.
Since the coconuts are evenly spaced around the circle, for any coconut there is always exactly one other coconut at its reflection across the -axis or the -axis.
Subqueries
Sensei's program contains subqueries, numbered from to . Each subquery is a command that changes the currently selected coconut. It has one of the following four forms.
Movement wraps around the circle: moving step counterclockwise goes from coconut to coconut , or otherwise from coconut to coconut . Likewise, moving step clockwise goes from coconut to coconut , or otherwise from coconut to coconut .
...But Sensei isn't going to execute just one subquery at a time.
Queries
The program also has queries that either execute some of these subqueries or change their contents. Each query is one of the following two types.
1 i j: Execute all subqueries from subquery through subquery , in increasing order of their numbers.
2 i j q or 2 i j q a: Replace every subquery from subquery through subquery with the same subquery.
Apparently coconut is selected initially. Starting from that state, the queries will be processed in order. Whenever a 1 i j query finishes, Sensei will call out the number of the coconut selected at that moment.
After each 1 i j query, the next query starts with the newly selected coconut still selected.
Objective
All right. I understand. In the end, there's only one thing I want to know.
“Which coconut numbers will Sensei call out, and in what order?”
Knowing those numbers in advance should give me an advantage. Let's find them in order by following all the given queries.
Lines 2 through contain subqueries through in order, one per line. Each line has one of the following two forms.
Then lines through contain the queries in execution order, one per line. Each line has one of the following three forms. ; ;
There is at least one query of type .