SHELL - Shell game

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.


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

hide comments
2012-04-11 16:34:47 MR. BEAN


Last edit: 2012-01-04 17:56:22
2012-04-11 16:34:47 Nakul Krishna
finally AC :) after a huge 19 WAs :(
@XeRon!X : thank you :D
2012-04-11 16:34:47 Nitin Sharma
more clarification is needed !!
2012-04-11 16:34:47 Aman Kumar
thanx @XeRon!X sir ! :)
i was taking no of testcases=10....which is wrong....ther are 10 input files with one test case each ! got loads of WAs cuz of dat.....
2012-04-11 16:34:47 Problem Solver
Thanks @XeRon!X
That worked.
2012-04-11 16:34:47 Goldie
please tell last case, every time getting WA :(

Thanks@XeRon!X got AC :)

Last edit: 2011-12-29 18:17:03
2012-04-11 16:34:47 Aman Kumar
anybody who's got AC please explain the last test case.........
2012-04-11 16:34:47 Problem Solver
Wow, seriously, even sigsegv doesn't work... Can anyone tell how to behave on last testcase?

For debugging use some_variable=1/0;
it would return sigfpe... but can't find what to return...

Last edit: 2011-12-29 02:44:45
2012-04-11 16:34:47 blashyrkh
It seems that special judge doesn't return NZEC. It returns WA instead, makes it difficult to debug.

Last edit: 2011-12-28 21:34:23
2012-04-11 16:34:47 gskhirtladze
very easy ...
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.