#include<iostream>
#include<queue>
#include<string>
using namespace std;
queue<int> q;
int main() {
    int n;
    cin >> n;
    int x, op;
    while (n--) {
        cin >> op;
        if (op == 1) {
            cin >> x;
            q.push(x);
        } else if (op == 2) {
            if (q.empty()) {
                cout << "ERR_CANNOT_POP" << endl;
            } else {
                q.pop();
            }
        } else if (op == 3) {
            if (q.empty()) {
                cout << "ERR_CANNOT_QUERY" << endl;
            } else {
                cout << q.front() << endl;
            }
        } else if (op == 4) {
            cout << q.size() << endl;
        }
    }
    return 0;
}