###数组模拟队列
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int q[N] , hh , tt = - 1;
//向队尾插入元素
void push(int x)
{
q[++ tt] = x;
}
//弹出队头元素
void pop()
{
hh ++;
}
//检查队列是否为空
bool empty_()
{
if (hh <= tt) return false;
else return true;
}
//查询队头元素
int query()
{
return q[hh];
//数组模拟队列还有一个好处就是可以查询队尾元素
//q[tt] 为对尾元素
}
int main()
{
int m , x;
cin>>m;
while (m --)
{
string op;
cin>>op;
if (op == "push")
{
cin>>x;
push(x);
}
else if (op == "pop") pop();
else if (op == "empty")
{
if (empty_())cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else
{
cout<<query()<<endl;
}
}
return 0;
}