Do the Shuffle

No attempts yetTime limit1sMemory limit128 MB

Problem

Those tiny music machines that play digital music are really small computers that store and play music files. A new portable music player called the C3MP is in development and will hit stores soon. In this problem you have to simulate a C3MP.

The C3MP holds 5 songs in memory, whose titles are always “A”, “B”, “C”, “D” and “E”. It also keeps a playlist, which is an ordering of all the songs. The player has 4 buttons that rearrange the playlist and play the songs.

Initially the playlist is A, B, C, D, E. The 4 buttons do the following:

  • Button 1: move the first song of the playlist to the end. For example, A, B, C, D, E becomes B, C, D, E, A.
  • Button 2: move the last song of the playlist to the start. For example, A, B, C, D, E becomes E, A, B, C, D.
  • Button 3: swap the first two songs of the playlist. For example, A, B, C, D, E becomes B, A, C, D, E.
  • Button 4: stop rearranging and output the playlist.

Input

The input is a sequence of button presses. Each press is given as two positive integers $b$ and $n$: $b$ is the button number ($1 \le b \le 4$) and $n$ is the number of times to press button $b$ ($1 \le n \le 10$). The two integers of a press may be separated by spaces or newlines.

The input always ends with the press $b = 4$, $n = 1$. When you read it, print the current playlist and stop. Button 4 is pressed exactly once, at the very end.

Output

Print the titles of the songs in the final playlist order, on one line, separated by single spaces.