Black Friday is coming. To get the best deal, people come to the mall on Thursday night and wait there until Friday morning. As the security officer, you are organizing people waiting in a line. There are people in the line. They are labeled with successive integers. The first person in line is labeled with number one, the second with number two, etc.
Since it's still long time before the mall is open, some people have to use the washroom. Each time a person needs to go to washroom, s/he steps out of the line and, after that, steps back into the line, though not necessarilly at the same position as before. Since there is only one washroom available, no person leaves the line before the previous person has returned. At any moment, there is at most one person missing from the line. During the whole night, washroom visits have occurred. Each visit is described by two integers
and
, denoting that the person labeled with
stepped out of the line and then stepped back into the line immediately in front of the person
.
After all the visits, you want to figure out the position of each person. You need to answer questions. Each question is one of the following types.
P X
: asking for the position of the person labeled with.
L X
: asking for the label of the person at position.
Can you write a program to answer all of the questions?
Input Specification
The first line contains one integer (
), the number of washroom visits.
Each of the following lines contains two integers
and
(
), describing one washroom visit where the person
stepped out of the line and stepped back into the line in front of the person
.
The second line contains one integer (
), the number of queries.
Each of the following lines contains one character (either
P
or L
) and an integer (
), describing a query.
Output Specification
For each query, your program should print one integer.
Constraints
Points | Additional constraints |
---|---|
| |
No additional constraints |
Sample Input
2
6 3
9 6
8
L 1
L 2
L 3
L 4
P 1
P 2
P 3
P 4
Sample Output
1
2
9
6
1
2
5
6
Comments