#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    while(cin>>n){
        stack<int>stk;
        while(n--){
            string s1,s2;
            cin>>s1;
            if(s1=="P"){
                cin>>s2;
                stk.push(stoi(s2));
            }else{
                if(s1=="A"){
                    if(stk.size()==0)cout<<"E"<<endl;
                    else cout<<stk.top()<<endl;
                }else{
                    if(stk.size()!=0)stk.pop();
                }
            }
        }
    }
}
// 64 位输出请用 printf("%lld")