#include <iostream>
#include <queue>
using namespace std;

int main() {
    queue<int>a;
    int n;
    cin >> n;
    int x;
    while(n--){
        cin >> x;
        if(x == 1) {
            int ai;
            cin >> ai;
            a.push(ai);
        }
        else if(x == 2 && !a.empty()){
            a.pop();
        }else if(x == 2 && a.empty()){
            cout << "ERR_CANNOT_POP" <<endl;
        }else if(x == 3 && !a.empty()) cout << a.front() << endl;
        else if(x == 3 && a.empty()) cout << "ERR_CANNOT_QUERY" <<endl;
        if(x == 4) cout << a.size() <<endl;
    }
}
// 64 位输出请用 printf("%lld")