#include<bits/stdc++.h>
using namespace std;
int t,n;
int a[1000010];
queue<int> q,p[1010],q1;
int main(){
while(1){
n++;
scanf("%d",&t);
if(!t)return puts(""),0;
printf("Scenario #%d\n",n);
q=q1;
for(int i=0;i<t;i++){
int x,y;p[t]=q1;
scanf("%d",&x);
while(x--){
scanf("%d",&y);
a[y]=i;
}
}
char c[15];
while(1){
scanf(" %s",&c);
if(c[0]=='S'){
puts("");
break;
}
if(c[0]=='E'){
int x;
scanf("%d",&x);
if(p[a[x]].empty())q.push(a[x]);
p[a[x]].push(x);
}
else{
printf("%d\n",p[q.front()].front());
p[q.front()].pop();
if(p[q.front()].empty())q.pop();
}
}
}
}
题目
蟹蟹泥门 qwq