As it’s known to all, there’s a cute girl named YJJ living in Sand River. One day when he was learning stack, he suddenly thought that it would be more interesting to add timestamp to each stack command, and wanted to delete the element(even it’s not the top one) as he wanted.
So he invented a stack called "YJJ's stack", which supports the following four command:
● push v t – push $v$ into YJJ’s stack, whose timestamp is $t$ ;
● delete v t – delete the uppermost element from the stack which is equal to $v$ , whose timestamp is $t$ ;
● pop t – pop the top element from YJJ’s stack, whose timestamp is $t$ ;
● query t – execute a query operation which is described below, whose timestamp is $t$ ;
There is an empty set of commands initially. When an command except query t arrives, we put the command into the set. When an command query t arrives, we process as follows:
1. Clear YJJ's stack .
2. Execute the command currently in the set whose timestamp is less than t .
3. The executing order of command is ordered by their timestamp in ascending order.
4. Print the top element in the stack.
Records of command are in arriving order, you are required to execute according to above rules. Another three constraints are made to simplify the problem :
1. All the pop and delete command are valid. In another word, if you do the process correctly, pop command will not be excuted on an empty YJJ’s stack and delete v command will not be excuted on an YJJ’s stack without v .
2. All timestamps are different.
3. The number of pop command is no more than $5$.