#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int que[N];
int front=0;
int gear=-1;
int m;
int main(){
memset(que, 0x00, sizeof que);
cin>>m;
string P;
int x;
while(m--){
cin>>P;
if(P=="push"){
cin>>x;
que[++gear]=x;
}
else if(P=="pop"){
++front;
}
else if(P=="empty"){
cout<<(front>gear?"YES":"NO")<<endl;
}
else if(P=="query"){
cout<<que[front]<<endl;
}
}
return 0;
}