SHELL - Shell game

no tags 

Your program is to play the traditional "shell" game (see Shell_game). The game is played as follows:

There is a person called an operator; he/she has 3 identical, non-transparent hollow objects - shells, and a metal ball, which he/she places under one of these objects. Then, the operator quickly swaps pairs of shells several times; if shells at positions A and B are swapped, and the ball is under the shell at position A, it moves under the shell at position B. In the end, you have to guess which shell the ball is under.

The shells are identical, and positions mean immediate position that you see (left will always denote the leftmost shell, not the shell that was leftmost in the beginning).

Input

The first line of input contains one string - "left", "center" or "right", denoting the position of the shell the ball is under in the beginning. The second line contains an integer N<=10, denoting the number of swaps. N lines follow, all of them contain 2 strings - positions of 2 shells which are swapped.

Output

Output position of the shell the ball is under after all swaps are performed.

Warning

Testing simulates the exact progress of an actual game! There are 10 testcases; in the last one only, N = 10. You're likely to get a WA on this last test case, even if your program seems correct. Remember, it's like an actual game!

Example

Input:
left
2
left right
right center

Output:
center

Explanation

In the beginning, the ball is under the left shell. After swap 1, it's under the right shell. After swap 2, it's under the center shell.


hide comments
Sampath Ravolaparthi: 2015-01-16 12:57:23

if Not for the comments I would have never got an AC

Jashan Goyal: 2014-07-19 12:04:15

Its bad to be serious...

Martijn Muijsers: 2013-10-21 01:06:55

Fantastic!

mystique_blue: 2013-07-02 14:55:18

Check the all submissions list.99% of those who got it in first try must have cheated.

Last edit: 2013-07-03 15:30:06
aqfaridi: 2013-08-04 04:45:42

i think problem statement & wiki reference is sufficient for the problem..
no need of any guess.(just read prob statement & reference carefully)

Last edit: 2013-06-26 16:41:40
BLANKRK: 2013-06-11 19:13:45

finaly got the trick :D got AC...

@nk!t: 2013-06-03 09:39:00

what is the last test case? And what should be the output format for it?
Please help...im getting WA...o.O


Added by:Xellos
Date:2011-12-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:people.ksp.sk/~acm