#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int q[N], hh, tt = -1;
void push(int x){
q[++tt] = x;
}
void pop(){
hh++;
}
void empty(){
if(hh <= tt) cout << "NO" << endl;
else cout << "YES" << endl;
}
void query(){
cout << q[hh] << endl;
}
int main(){
int m;
cin >> m;
while(m--){
string s;
cin >> s;
if(s == "push"){
int x;
cin >> x;
push(x);
}
else if(s == "empty"){
empty();
}
else if(s == "query"){
query();
}
else{
pop();
}
}
return 0;
}
# 队列
//在队尾插入元素,在队头弹出元素
int q[N], hh, tt = -1;
//插入
q[++tt] = x;
//弹出
hh++;
//判断队列是否为空
if(hh <= tt) not empty;