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 Jakub ©afin
hendrik: if it should be moved to tutorial, why did less than 200 people solve it?
Fallen: yes, and don't waste your time programming, is that what you wanted to say?
2012-04-11 16:34:47 Vamsi Kavala
STUPID problem!! Don't waste your time solving this..
2012-04-11 16:34:47 hendrik
Should be moved to tutorial.
2012-04-11 16:34:47 Rishi Mukherje
after so many WAs got AC..:)...the problem description is really good...:)..never clicked in my mind...

Last edit: 2012-01-07 15:55:10
2012-04-11 16:34:47 .:abacus:.
there were 2 more test cases in slovac version
left
3
right center
right center
center right
left


center
3
center right
center left
center right
center

and thanx @XeRon!X

Last edit: 2012-01-05 21:54:04
2012-04-11 16:34:47 Jakub ©afin
with or without comments' help?
2012-04-11 16:34:47 Secret
got AC in 1st time :P
2012-04-11 16:34:47 Jakub ©afin
I'm afraid I don't see it written anywhere that position can only be left/center/right, nor that you're supposed to output only left/center/right. If the ball has no valid position (if you choose left/center/right, your answer is wrong), then, in general, its position is something like dividing by zero in arithmetics. What is the correct, answer, then? It's silence, which, in this case, is an empty output file. That to my explanation about the way I understood the description.

Also, this contains no less useful information than the Slovak version on the original site (I translated it). I competed at that, and managed to solve it w/o any help, and there are even (quite many) people who managed to solve it within the 3 hrs time limit along with some other, much harder (although less tricky) ones, so the one at fault for not being able to solve this is not the problem itself!

And before you think about there being 10 test cases in 1 file, read the input description and sample again.

Last edit: 2011-12-30 20:07:14
2012-04-11 16:34:47 conioh
thanx @XeRon!X got AC
2012-04-11 16:34:47 RAJDEEP GUPTA
Aman Kumar is right. There are 10 files. Not 10 test cases in a single file.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.