n = int(input().strip()) queue = [] for _ in range(n): num = list(map(int,input().strip().split(" "))) if num[0] == 1: queue.append(num[1]) elif num[0] == 2: if len(queue) == 0: print("ERR_CANNOT_POP") else: queue.pop(0) elif num[0] == 3: if queue: print(queue[0]) else: print("ERR_CANNOT_QUERY") elif num[0] == 4: print(len(queue))