函数式编程
M = int(input())
M_list= []
for i in range(M):
M_list.append(input())
def push(x):
global stack
stack.append(x)
def pop():
global stack
del stack[-1]
def empty():
global stack
if stack == []:
print('YES')
else:
print('NO')
def query():
print(stack[-1])
def ans(string):
global stack
string = list(string.split())
classes, x = string[0], string[-1]
if classes == 'push':
push(x)
if classes == 'pop':
pop()
if classes == 'empty':
empty()
if classes == 'query':
query()
stack = []
for i in M_list:
ans(i)