考点:栈
#include<bits/stdc++.h>
using namespace std;
const int MAXSIZE=1001;
int main() {
int n;
while(cin>>n) {
stack<int> s;
char c;
int x;
if(n==0) {
break;
}
for(int i=0; i<n; i++) {
getchar();
cin>>c;
if(c=='A') {
if(s.empty()) {
cout<<"E"<<endl;
} else {
cout<<s.top()<<endl;
}
} else if(c=='P') {
cin>>x;
s.push(x);
} else if(c=='O') {
if(!s.empty()) {
s.pop();
}
}
}
cout<<endl;
}
return 0;
}