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

int main() {
    int n;
    cin>>n;
    int a,b,x;
    queue<int> q;
    for (int i=0; i<n; ++i) {
        cin>>a;
        switch (a) {
            case 1:
                cin>>x;
                q.push(x);
                break;
            case 2:
                if (!q.empty()) {
                    q.pop();
                }else {
                    cout<<"ERR_CANNOT_POP"<<endl;
                }
                break;
            case 3:
                if (q.empty()) {
                    cout<<"ERR_CANNOT_QUERY"<<endl;
                }else {
                    cout<<q.front()<<endl;
                }
                break;
            case 4:
                cout<<q.size()<<endl;
                break;
        }
    }
}
// 64 位输出请用 printf("%lld")