Fitness

Simulate moves around 8 circularly numbered stations and print the visited sequence, marking it reject if fewer than 5 distinct stations appear or any station repeats.

Easy3SimulationImplementationArrayHash mapInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Hilary likes to exercise. A reserve near her home has 8 fitness stations arranged in a circle. As the picture shows, they are numbered 1 to 8 clockwise, and station 8 is followed by station 1 again. Every day Hilary visits at least 5 of them.

Her daughter Catherine writes the daily plans. A plan gives one starting station and a series of moves. Catherine has written many plans but has not checked them. Decide whether a plan visits at least 5 different stations and never visits the same station twice.

Input

The input describes a single plan. The first line has the starting station number SS (0<S<90 < S < 9).

Each of the following lines holds one move, written as a letter followed by a digit. The letter C means clockwise and A means anticlockwise. The digit NN is how many stations to move in that direction (1N71 \le N \le 7). The last line is #; do not process it. A plan has at most 50 moves, and it may have none.

Output

Print the stations the plan visits, in visit order, separated by single spaces on one line. The starting station counts as the first visit. If the plan visits fewer than 5 different stations, or visits some station more than once, append a space and the word reject after the list.