If you are an average football fan, you probably know that obtaining tickets for this year's World Cup in
Germany was an almost impossible task. Greedy organizers and football federations grabbed the majority of
available tickets and divided them among sponsors, friends and family members. As a result, jet setters have
flooded the venues, while die-hard fans sit at home enjoying the games between advertisements featuring crappy
beer and sugar-free chewing gum.
A couple of tickets are left for the final game and a huge queue has formed in front of the ticket office. As fans
were arriving, they were labeled with successive integers. The first person in queue was labeled with number one,
the second with number two, etc.
Since the fans arrived the night before, they had to wait for a long time before the ticket counter was open and,
naturally, some of them had to use the restroom. Each time a person needs to use the restroom, he/she steps
out of the queue and, after completing the task, steps back into the queue, though not necessarily at the same
position as before. Since there is only one restroom available, no person leaves the queue before the previous
person has returned (hence, at any moment there is at most one person missing from the queue).
During the course of the night, a total of N restroom visits have occurred. Each visit is described by two positive
integers A and B, denoting that the person labeled A stepped out of the queue and then stepped back into the
queue immediately in front of the person labeled B. Now that all the visits have completed, the officials have
to answer a series of questions. Each question is either of the form 'P X', asking for the position of the person
labeled X, or of the form 'L X', asking for the label of the person at position X.
The first person in queue is considered to be at position one, the second at position two, etc.
Write a program that, given the description of the visits and a number of questions, answers all of the
questions.