Musical Chairs

Simulate musical chairs: each round every remaining player shifts M seats clockwise, the player at seat S is eliminated, and seats are renumbered until R rounds pass.

Easy3SimulationImplementationArrayMathInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Musical chairs is a game often played at children's parties. The players sit in a circle facing outwards. When the music starts, everyone stands up and walks clockwise around the chairs. One chair is taken away, and when the music stops every player tries to sit on one of the remaining chairs. The player who fails to sit down is out, and the game continues until only one player is left. That player is the winner.

Each round works as follows. At the start of a round there are kk seats, numbered 11 to kk in the clockwise direction. Given the number SS of the seat to be removed and the number of moves MM, every player moves MM times clockwise. One move takes a player to the seat with the next number, and a move from seat kk takes a player to seat 11. Once the moves are finished, the player who ends up at seat SS is eliminated. The remaining players keep their clockwise order, and their seats are renumbered 11 to k1k-1.

At the start of the game the players occupy seats 11 to NN in the order they are given in the input.

Input

The first line contains the number of players NN (1<N151 < N \le 15).

Each of the next NN lines contains one player's name. A name contains no spaces and is at most 10 characters long. The players occupy seats 11 to NN in this order.

The next line contains the number of rounds to process, RR (0<R<N0 < R < N).

Each of the next RR lines contains two integers SS and MM separated by a space. SS is the number of the seat removed in that round, and 1Sk1 \le S \le k where kk is the number of seats at the start of that round. MM is the number of moves made before the music stops (0<M300 < M \le 30).

Output

After each round, print one line in this format.

<name> has been eliminated.

Here <name> is the name of the player who finds no seat, that is, the player who ends up at the seat that was removed.

After all the given rounds are processed, print one more line. If a single player remains, print

<name> has won.

If two or more players remain, print

Players left are <name list>.

<name list> holds the name of every player not yet eliminated, in the same order as in the input, separated by single spaces.