#include <bits/stdc++.h>
#define MOD 998244353
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define ui unsigned int
using namespace std;
const int maxn = 1e6+9;
int main()
{
int n;
cin >> n;
queue<int>q;
for (int i = 1; i <= n; i++)
{
char s;
int x;
cin >> s;
if (s == '1')
{
cin >> x;
q.push(x);
}
else if (s == '2')
{
if (q.empty()) cout << "ERR_CANNOT_POP\n";
else q.pop();
}
else if (s == '3')
{
if (q.empty()) cout << "ERR_CANNOT_QUERY\n";
else cout << q.front() << "\n";
}
else if (s == '4') cout << q.size();
}
return 0;
}