#include<iostream> #include<stack> using namespace std; int main() { int n,c=0,x; char op; while(scanf("%d ",&n)!=EOF&&n!=0) { stack<int> a; if(c>0) printf("\n"); while(n--) { scanf("%c ",&op); if(op=='P') { scanf("%d ",&x); a.push(x); } else if(op=='O') { if(!a.empty()) a.pop(); } else if(op=='A') { if(!a.empty()) printf("%d\n",a.top()); else printf("E\n"); } } c++; } return 0; }(•̀ᴗ•́)و