n = int(input())
from collections import deque
q = deque()
for _ in range(n):
    a = input().split()
    if a[0] == '1':
        q.append(int(a[1]))
    elif a[0] == '2':
        if q:
            q.popleft()
        else:
            print('ERR_CANNOT_POP')
    elif a[0] == '3':
        if q:
            print(q[0])
        else:
            print('ERR_CANNOT_QUERY')
    elif a[0] == '4':
        print(len(q))