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

京公网安备 11010502036488号