#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int que[10010];
int hh=0,tt=-1;
void push(int x)
{
que[++tt]=x;
}
void pop()
{
if(hh>tt) puts("ERR_CANNOT_POP\n");
else hh++;
}
void query()
{
if(hh>tt) puts("ERR_CANNOT_QUERY\n");
else printf("%d\n",que[hh]);
}
int size()
{
return tt-hh+1;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int s;
scanf("%d",&s);
if(s==1)
{
int x;
scanf("%d",&x);
push(x);
}
else if(s==2) pop();
else if(s==3) query();
else printf("%d\n",size());
}
return 0;
}