#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int n;
int main(){
scanf("%d",&n);
while (n--){
int x,y;
scanf("%d",&x);
if (x == 1){
scanf("%d",&y);
q.push(y);
}else if (x == 2){
if (q.empty()){printf("ERR_CANNOT_POP\n");
}else{
q.pop();
}
}else if (x == 3){
if (q.empty()){printf("ERR_CANNOT_QUERY\n");
}else{
printf("%d\n",q.front());
}
}else{
printf("%d",q.size());
}
}
return 0;
}