ADA and Queue#11789

ADA and Queue

1 second
128 megabytes
Easy

Huseyn has many things to do at ADA University. He puts them into his queue. Anyway he is very indecisive, so sometimes he uses the front, sometimes the back and sometimes he decides to reverse it.

Input

The first line contains the number of queries q~(1 \le q \le 10^5). Each of them contains one of the following commands

  • back — Print number from back and then erase it;

  • front — Print number from front and then erase it;

  • reverse — Reverses all elements in queue;

  • push_back n — Add element n~(0 \le n \le 100) to back;

  • toFront n — Put element n~(0 \le n \le 100) to front

Output

For each back / front query print appropriate number.

If the queue is empty when processing such a query, print "Nothing to do in ADA" instead.

Examples

Example 1

Loading
Loading