#include <stdio.h> int main() { int n,i; while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case int shuzu[1000]; static int end=0; for(i=0;i<n;i++){ char S; scanf("%c",&S); if(S=='A'){ if(end>0){ printf("%d\n",shuzu[end-1]); }else{ printf("E\n"); } }else if(S=='P'){ scanf("%d",&shuzu[end]); end+=1; }else if(S=='O'){ if(end>0){ end-=1; } } } } return 0; }