1 #include<cstdio> 2 #include<cstring> 3 #define MAXM 9 4 #define MAXN 1000010 5 int q[MAXN],rp[MAXN]; 6 int main() 7 { 8 int c,front,rear,size,now; 9 char s[MAXM]; 10 scanf("%d",&c); 11 while(c--) 12 { 13 scanf(" %s",s); 14 front=now=0; 15 rear=size=-1; 16 while(scanf(" %s",s),strcmp(s,"END")) 17 { 18 if(s[0]=='C') 19 { 20 size++; 21 scanf(" %s%d",s,&rp[size]); 22 for(;front<=rear&&rp[size]>=rp[q[rear]];rear--); 23 q[++rear]=size; 24 } 25 else if(s[0]=='G') 26 { 27 now++; 28 for(;front<=rear&&q[front]<now;front++); 29 } 30 else 31 { 32 if(front<=rear) 33 printf("%d\n",rp[q[front]]); 34 else 35 puts("-1"); 36 } 37 } 38 } 39 return 0; 40 }