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