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