{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the queue in front of the Mensa is a team queue, for example. \n \u003cbr\u003eIn a team queue each element belongs to a team. If an element enters the queue, it first searches the queue from head to tail to check if some of its teammates (elements of the same team) are already in the queue. If yes, it enters the queue right behind them. If not, it enters the queue at the tail and becomes the new last element (bad luck). Dequeuing is done like in normal queues: elements are processed from head to tail in the order they appear in the team queue. \n \u003cbr\u003e \n \u003cbr\u003eYour task is to write a program that simulates such a team queue. \n \u003cbr\u003e \n \u003cbr\u003e \n\u003c/div\u003e\n模拟食堂排队打饭,当一个人过来时,先看看有没有自己班里的同学,如果有,就会插到班里同学的最后面。如果没有自己班里的同学,就排到队伍的最后面。模拟这个过程,需要输出队首的元素。\n\n\n\n\n"}},{"title":"Input","value":{"format":"HTML","content":"The input will contain one or more test cases. Each test case begins with the number of teams t (1\u0026lt;\u003dt\u0026lt;\u003d1000). Then t team descriptions follow, each one consisting of the number of elements belonging to the team and the elements themselves. Elements are integers in the range 0 - 999999. A team may consist of up to 1000 elements. \n\u003cbr\u003e \n\u003cbr\u003eFinally, a list of commands follows. There are three different kinds of commands: \n\u003cbr\u003e \n\u003cbr\u003eENQUEUE x - enter element x into the team queue \n\u003cbr\u003eDEQUEUE - process the first element and remove it from the queue \n\u003cbr\u003eSTOP - end of test case \n\u003cbr\u003eThe input will be terminated by a value of 0 for t. \n\u003cbr\u003e \n\u003cbr\u003e\n有多组测试数据,每组数据第一行一个整数,表示班级的数量t。\u003cbr\u003e\n接下来t行,每行第一个数表示该班级的人数k,接下来跟着k个整数,表示每个学生的编号。\u003cbr\u003e\n学生的编号范围是[0,999999],一个班级最多1000个人。\u003cbr\u003e\n接下来是指令,以下3个之一:\u003cbr\u003e\nENQUEUE x :表示一个编号为x的人来到队伍中;\u003cbr\u003e\nDEQUEUE : 输出队首的元素的编号,并将其删除。\u003cbr\u003e\nSTOP:表示这组测试数据结束。\n\nt\u003d0时,所有的测试数据结束。"}},{"title":"Output","value":{"format":"HTML","content":"For each test case, first print a line saying \"Scenario #k\", where k is the number of the test case. Then, for each DEQUEUE command, print the element which is dequeued on a single line. Print a blank line after each test case, even after the last one. \n\u003cbr\u003e\n对于每组测试数据,先输出\"Scenario #k\",k表示第几组测试数据。\n对于每个 DEQUEUE,输出相应的结果。\n每组测试数据,最后输出一个空行,最后一组数据,也需要输出空行。"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e2\n3 101 102 103\n3 201 202 203\nENQUEUE 101\nENQUEUE 201\nENQUEUE 102\nENQUEUE 202\nENQUEUE 103\nENQUEUE 203\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nSTOP\n2\n5 259001 259002 259003 259004 259005\n6 260001 260002 260003 260004 260005 260006\nENQUEUE 259001\nENQUEUE 260001\nENQUEUE 259002\nENQUEUE 259003\nENQUEUE 259004\nENQUEUE 259005\nDEQUEUE\nDEQUEUE\nENQUEUE 260002\nENQUEUE 260003\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nSTOP\n0\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003eScenario #1\n101\n102\n103\n201\n202\n203\n\nScenario #2\n259001\n259002\n259003\n259004\n259005\n260001\u003c/pre\u003e"}}]}