Price of fertilizers in the world are raising! Adding Jinkela in fertilizer, one bag can cover two bags!!
People are lining up in a queue to buy Jinkela. Each person is given a unique id x. Lining up is tedious, so everyone wants to cut in line! These people follow some rule when they cut in line:
when a person enters the queue,
Some people may leave the queue without buying Jinkela, and these people may join the queue again.
You are curious about the order people get their Jinkela. Given the status of the queue, whenever someone gets his Jinkela, output his id.
Refer to the sample IO for example if you don't understand the rule.
The first line contains two integers n m: the number of commands and the number of friend groups.
The following m lines are the friend groups, where, in each line, the first integer k is the number of the group members, and the next k integers are the id's of the group members. (Each person belongs to at most one group of friends.)
The following n lines are the commands, which can be:
Testcases:
In addition, for each "LEAVE x" command, it is guaranteed that the person with id x must be in the queue.
The 13rd & 14th testcases are more challenging. For the LEAVE commands, find some way to avoid "leaving the queue immediately".
For each DEQUEUE command, please output the id of the person who buys his Jinkela and leaves the queue. If the queue is empty, output "The queue is empty".
Each output occupies a single line. Remember to add a '\n' at the end.