Write a program that processes a large number of deques. A deque is a "queue with two ends".
The first line contains the total number of commands (0 \leq n \leq 150{,}000). Each of the next lines contains a command description:
pushfront A B — insert the number at the front of deque ;
pushback A B — insert the number at the back of deque ;
popfront A — remove the first element from deque ;
popback A — remove the last element from deque .
In each command, and are integers from to inclusive.
For each popfront or popback command, print the removed number. It is guaranteed that before every remove operation the corresponding deque is not empty.
Example 1