https://www.acmicpc.net/problem/7662
import heapq
import sys
input = sys.stdin.readline
testCase = int(input())
for _ in range(testCase):
n = int(input())
maxArr = []
minArr = []
visited = [1] * n
for i in range(n):
cmd, num = map(str, input().split())
num = int(num)
if cmd == 'I':
heapq.heappush(minArr, (num, i))
heapq.heappush(maxArr, (-num, i))
else:
if num == -1:
if minArr:
visited[heapq.heappop(minArr)[1]] = 0
elif num == 1:
if maxArr:
visited[heapq.heappop(maxArr)[1]] = 0
while minArr and visited[minArr[0][1]] == 0:
heapq.heappop(minArr)
while maxArr and visited[maxArr[0][1]] == 0:
heapq.heappop(maxArr)
if minArr == []:
print("EMPTY")
else:
print(-maxArr[0][0], minArr[0][0])