#include<bits/stdc++.h>
using namespace std;
queue<int> q;
int n,t,x;
int main(){
cin>>n;
while(n--){
cin>>t;
if(t==1){
cin>>x;
q.push(x);
}
else if(t==2){
if(!q.empty()){
q.pop();
}
else{
cout<<"ERR_CANNOT_POP";
}
}
else if(t==3){
if(!q.empty()){
cout<<q.front()<<endl;
}
else{
cout<<"ERR_CANNOT_QUERY";
}
}
else{
cout<<q.size()<<endl;
}
}
return 0;
}