#include <iostream> #include <stack> using namespace std; stack<int> stk; int main() { int n; while (cin >> n) { char op; int num; while(n --){ cin >> op; if(op == 'P'){ cin >> num; stk.push(num); } else if (op == 'A') { if(!stk.empty()) cout << stk.top() << endl; else cout << 'E' << endl; } else if (op == 'O'){ if(!stk.empty()) stk.pop(); } } } return 0; } // 64 位输出请用 printf("%lld")