N = 100010
queue = [0] * N
head, tail = 0, 0
M = int(input())
for _ in range(M):
s = input().split()
if s[0] == "push":
x = int(s[1])
queue[tail] = x
tail += 1
elif s[0] == "pop":
head += 1
elif s[0] == "query":
print(queue[head])
else:
if head == tail:
print("YES")
else:
print("NO")