#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int stk[N], tt;
void query(){
if(tt) cout << stk[tt] << endl;
}
void pop(){
if(tt) tt--;
}
void push(int x){
stk[++tt] = x;
}
int main(){
int m;
cin >> m;
while(m--){
string str;
int x;
cin >> str;
if(str == "push"){
cin >> x;
push(x);
}
else if(str == "pop") pop();
else if(str == "query") query();
else if(tt) cout << "NO" << endl;
else cout << "YES" << endl;
}
return 0;
}