import heapq
n=int(input())
heap=[]
for i in range(n):
s=list(map(int,input().split()))
if int(s[0])==1:
heapq.heappush(heap,s[1])
elif s[0]==2:
print(heap[0])
elif s[0]==3:
heapq.heappop(heap)

import heapq
n=int(input())
heap=[]
for i in range(n):
s=list(map(int,input().split()))
if int(s[0])==1:
heapq.heappush(heap,s[1])
elif s[0]==2:
print(heap[0])
elif s[0]==3:
heapq.heappop(heap)