#include<bits/stdc++.h>
using namespace std;



int main(){
	int n;  cin >> n;
	queue<int> q;
	
	while(n--){
		int a;  cin >> a;
		
		if(a == 1){
			int x;  cin >> x;
			q.push(x);
		}
		
		if(a == 2){
			if(!q.empty())
			q.pop();
			else
			cout << "ERR_CANNOT_POP" << endl;
		}
		
		if(a == 3){
			if(!q.empty())
			cout << q.front() << endl;
			else
			cout << "ERR_CANNOT_QUERY" << endl;
		}
		
		if(a == 4){
			cout << q.size() << endl;
		}
	}
	return 0;
}