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