第6章-2 一帮一
n = int(input())
lst1 = []
lst2 = []
lst3 = []
for i in range(n):
t = input().split()
lst3.append(t[1])
if t[0] == '0':
lst1.append(t[1])
else:
lst2.append(t[1])
for i in range(int(n / 2)):
if lst3[i] in lst1:
j = lst1.index(lst3[i])
print(lst3[i] + ' ' + lst2[-(j + 1)])
else:
j = lst2.index(lst3[i])
print(lst3[i] + ' ' + lst1[-(j + 1)])