Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.

The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest.

Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests.


-----Input-----

The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 10 000, n ≥ 2m) — the number of participants of the qualifying contest and the number of regions in Berland.

Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).

It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct.


-----Output-----

Print m lines. On the i-th line print the team of the i-th region — the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.


-----Examples-----
Input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503

Output
Sidorov Ivanov
Andreev Semenov

Input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503

Output
?
Andreev Semenov



-----Note-----

In the first sample region teams are uniquely determined.

In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.

Difficulty: EASY
Tags: Sorting

Constructive algorithms
Skill types: Sorting

Starter code:

Solutions:
def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
(n, m) = MAP()
d = {}
d2 = {}
k = {}
vis = [0] * (m + 1)
for i in range(n):
	l = input().split()
	name = l[0]
	number = int(l[1])
	points = int(l[2])
	if number not in d:
		d[number] = [[name, points]]
	else:
		d[number].append([name, points])
res = []
for i in range(1, m + 1):
	d[i].sort(key=lambda x: x[1], reverse=True)
	if len(d[i]) == 2:
		x1 = d[i][0][0]
		x2 = d[i][1][0]
		res.append(x1 + ' ' + x2)
	elif d[i][1][1] == d[i][2][1]:
		res.append('?')
	else:
		x1 = d[i][0][0]
		x2 = d[i][1][0]
		res.append(x1 + ' ' + x2)
for i in res:
	print(i)


from collections import defaultdict
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
D = defaultdict(list)
for i in range(n):
	(a, b, c) = input().split()
	(b, c) = (int(b) - 1, int(c))
	D[b].append((c, a))
	D[b] = sorted(D[b], reverse=True)[:3]
for i in range(m):
	if len(D[i]) == 2:
		print(D[i][0][1], D[i][1][1])
		continue
	(a, b, c) = D[i]
	if c[0] == b[0] or c[0] == a[0]:
		print('?')
	else:
		print(a[1], b[1])


import itertools as it
(n, m) = map(int, input().split(' '))
inputs = []
for i in range(0, n):
	s = input().split(' ')
	inputs.append((int(s[1]), int(s[2]), s[0]))
data = []
for (k, g) in it.groupby(sorted(inputs), lambda x: x[0]):
	data.append(sorted(g, key=lambda x: x[1], reverse=True))
for i in range(0, m):
	if len(data[i]) > 2 and data[i][1][1] == data[i][2][1]:
		print('?')
	else:
		print(data[i][0][2] + ' ' + data[i][1][2])


def bubblesort(sta, n):
	for i in range(n):
		noswap = 1
		for j in range(len(sta) - 1, i, -1):
			if sta[j][1] > sta[j - 1][1]:
				(sta[j], sta[j - 1]) = (sta[j - 1], sta[j])
				noswap = 0
		if noswap:
			break
	return sta
(n, m) = [int(i) for i in input().split()]
reg = []
for i in range(m):
	reg.append([])
for i in range(n):
	p = list(input().split())
	p[1] = int(p[1])
	p[2] = int(p[2])
	reg[p[1] - 1].append([p[0], p[2]])
for i in range(m):
	a = bubblesort(reg[i], 3)
	if len(a) == 2:
		print(a[0][0], a[1][0])
	elif a[1][1] == a[2][1]:
		print('?')
	else:
		print(a[0][0], a[1][0])


def f(x):
	return x[1]
L = [int(s) for s in input().split()]
(n, m) = (L[0], L[1])
Result = [[] for i in range(m)]
for i in range(n):
	Name = [s for s in input().split()]
	region = int(Name[1]) - 1
	Result[region].append([Name[0], int(Name[2])])
for i in range(m):
	R = []
	X = sorted(Result[i], key=f)[::-1]
	R.append(X[0][0])
	R.append(X[1][0])
	if len(X) > 2 and X[2][1] == X[1][1]:
		print('?')
	else:
		print(' '.join(R))


(n, m) = [int(i) for i in input().split()]
list_in = [[] for i in range(m)]
for i in range(n):
	(name, region, score) = input().split()
	region = int(region)
	score = int(score)
	list_in[region - 1].append([name, score])
for i in range(m):
	list_opt = list_in[i]
	list_opt = sorted(list_opt, key=lambda list_opt: list_opt[1], reverse=True)
	if len(list_opt) < 3:
		print(list_opt[0][0], list_opt[1][0])
	elif list_opt[1][1] == list_opt[2][1]:
		print('?')
	else:
		print(list_opt[0][0], list_opt[1][0])


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	(name, i, q) = input().split()
	i = int(i)
	q = int(q)
	if i in d:
		d[i].append((q, name))
	else:
		d[i] = [(q, name)]
for i in range(1, m + 1):
	d[i].sort(reverse=True)
	if len(d[i]) > 2 and d[i][1][0] == d[i][2][0]:
		print('?')
	else:
		print(d[i][0][1], d[i][1][1])


from sys import stdin

class SchoolBoy:

	def __init__(self, name, region, score):
		self.name = name
		self.region = int(region)
		self.score = int(score)

class Region:

	def __init__(self, region_code):
		self.regionCode = region_code
		self.boys = []

	def add_school_boy(self, school_boy):
		isinstance(school_boy, SchoolBoy)
		self.boys.append(school_boy)

	def winner_team(self):
		if len(self.boys) > 2:
			self.boys.sort(key=lambda b: b.score, reverse=True)
			if self.boys[1].score == self.boys[2].score:
				return '?'
		return '%s %s' % (self.boys[0].name, self.boys[1].name)
(n, m) = [int(x) for x in next(stdin).split()]
regions = []
for i in range(m):
	regions.append(Region(i))
for i in range(n):
	(name, region, score) = stdin.readline().split()
	sb = SchoolBoy(name, int(region) - 1, int(score))
	regions[sb.region].add_school_boy(sb)
for i in range(m):
	print(regions[i].winner_team())


(n, m) = map(int, input().split())
a = [[] for i in range(m)]
for i in range(n):
	x = input().split()
	a[int(x[1]) - 1].append([int(x[2]), x[0]])
for i in range(m):
	x = sorted(a[i], reverse=True)
	if len(x) == 2:
		print(' '.join([x[0][1], x[1][1]]))
		continue
	if x[1][0] > x[2][0]:
		print(' '.join([x[0][1], x[1][1]]))
	else:
		print('?')


(n, m) = map(int, input().split())
dic = {}
for i in range(n):
	(name, reg, score) = input().split()
	score = int(score)
	reg = int(reg)
	if reg in dic:
		dic[reg].append([score, name])
	else:
		dic[reg] = [[score, name]]
for i in range(1, m + 1):
	dic[i].sort(reverse=True)
	if len(dic[i]) == 2 or dic[i][1][0] > dic[i][2][0]:
		print(dic[i][0][1], dic[i][1][1])
	else:
		print('?')


(n, m) = map(int, input().split())
a = [[] for i in range(m)]
c = []
for i in range(n):
	(name, reg, score) = input().split()
	reg = int(reg)
	score = int(score)
	a[reg - 1].append((name, reg, score))
for j in range(m):
	a[j].sort(key=lambda x: -x[2])
for i in range(m):
	if a[i][0][2] == a[i][1][2]:
		value = a[i][0][2]
		count = 0
	else:
		value = a[i][1][2]
		count = 0
	for j in range(1, len(a[i])):
		if a[i][j][2] == value:
			count += 1
	a[i].append(count)
for i in range(m):
	if a[i][-1] > 1:
		print('?')
	else:
		print(a[i][0][0], a[i][1][0])


tokens = []
tokens_next = 0
import sys
file = sys.stdin

def next_str():
	global tokens, tokens_next
	while tokens_next >= tokens.__len__():
		tokens = file.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
n = nextInt()
m = nextInt()
regions = [[] for i in range(n)]
for _ in range(n):
	(name, round, score) = (next_str(), nextInt(), nextInt())
	regions[round].append((score, name))
for r in regions:
	r.sort(reverse=True)
	if len(r) < 2:
		continue
	if len(r) > 2 and r[1][0] == r[2][0]:
		print('?')
	else:
		print(r[0][1], r[1][1])


(n, m) = map(int, input().split(' '))

def De(s):
	p = s.split(' ')
	return (p[0], int(p[1]) - 1, int(p[2]))
l = [[] for _ in range(m)]
t = [0] * m
for _ in range(n):
	(p, r, s) = De(input())
	if len(l[r]) < 1:
		l[r].append((p, s))
	elif len(l[r]) < 2:
		if s > l[r][0][1]:
			l[r].insert(0, (p, s))
		else:
			l[r].append((p, s))
	elif len(l[r]) < 3:
		if s > l[r][0][1]:
			l[r].insert(0, (p, s))
		elif s > l[r][1][1]:
			l[r].insert(1, (p, s))
		else:
			l[r].append((p, s))
	else:
		if s > l[r][0][1]:
			l[r].insert(0, (p, s))
		elif s > l[r][1][1]:
			l[r].insert(1, (p, s))
		elif s > l[r][2][1]:
			l[r].insert(2, (p, s))
		else:
			l[r].append((p, s))
		l[r].pop()
for i in range(m):
	if len(l[i]) > 2 and l[i][1][1] == l[i][2][1]:
		print('?')
	else:
		print(l[i][0][0], l[i][1][0])


(n, m) = [int(i) for i in input().split()]
participant = []
for i in range(m):
	participant.append([])
for i in range(n):
	(surname, region, point) = [char for char in input().split()]
	region = int(region)
	point = int(point)
	participant[region - 1].append([point, surname])
for i in range(m):
	participant[i].sort()
	if len(participant[i]) >= 3:
		if participant[i][-2][0] == participant[i][-3][0]:
			print('?')
		else:
			print('%s %s' % (participant[i][-1][1], participant[i][-2][1]))
	else:
		print('%s %s' % (participant[i][-1][1], participant[i][-2][1]))


(a, b) = (int(i) for i in input().split())
t = {}
for i in range(a):
	p = input().split()
	s = int(p[1])
	if s in t.keys():
		t[s].append([p[0], int(p[2])])
	else:
		t[s] = [[p[0], int(p[2])]]
m = t.keys()
for i in m:
	t[i].sort(key=lambda x: -x[1])
for i in range(b):
	if len(t[i + 1]) >= 3 and t[i + 1][1][1] != t[i + 1][2][1]:
		print(t[i + 1][0][0], t[i + 1][1][0])
	elif len(t[i + 1]) == 2:
		print(t[i + 1][0][0], t[i + 1][1][0])
	else:
		print('?')


(n, m) = map(int, input().split())
ls = [[] for i in range(m)]
for i in range(n):
	(a, b, c) = input().split()
	(b, c) = (int(b), int(c))
	ls[b - 1].append([a, c])
for i in range(m):
	ls[i].sort(key=lambda x: x[1], reverse=True)
	if len(ls[i]) > 2 and ls[i][1][1] == ls[i][2][1]:
		print('?')
	else:
		print(ls[i][0][0], ls[i][1][0])


(n, m) = map(int, input().split(' '))
l = list()
d = {}
for i in range(m):
	d[i + 1] = []
for i in range(n):
	(a, b, c) = input().split()
	b = int(b)
	c = int(c)
	d[b] += [(c, a)]
for j in range(m):
	t = sorted(d[j + 1])[::-1]
	if int(len(t)) > 2 and t[1][0] == t[2][0]:
		print('?')
	else:
		print(t[0][1] + ' ' + t[1][1])


(n, m) = map(int, input().split())
d = {}
for i in range(1, m + 1):
	d[i] = []
for i in range(n):
	(s, r, p) = map(str, input().split())
	(r, p) = (int(r), int(p))
	d[r].append([p, s])
for key in d:
	d[key] = sorted(d[key])
	d[key].reverse()
for key in d:
	try:
		if d[key][1][0] == d[key][2][0]:
			print('?')
		else:
			print(d[key][0][1], d[key][1][1])
	except:
		print(d[key][0][1], d[key][1][1])


(n, m) = map(int, input().split())
marks = [[-1, -1, -1] for i in range(m)]
names = [['', ''] for i in range(m)]
for i in range(n):
	x = input().split()
	a = int(x[1]) - 1
	b = int(x[2])
	if b > marks[a][0]:
		marks[a][2] = marks[a][1]
		marks[a][1] = marks[a][0]
		names[a][1] = names[a][0]
		marks[a][0] = b
		names[a][0] = x[0]
	elif b > marks[a][1]:
		marks[a][2] = marks[a][1]
		marks[a][1] = b
		names[a][1] = x[0]
	elif b > marks[a][2]:
		marks[a][2] = b
for i in range(m):
	if marks[i][1] == marks[i][2]:
		print('?')
	else:
		print(names[i][0], names[i][1])


def main():
	from sys import stdin
	(n, m) = map(int, input().split())
	l = [[] for _ in range(m)]
	for (s, a, b) in map(str.split, stdin.read().splitlines()):
		l[int(a) - 1].append((int(b), s))
	for (i, r) in enumerate(l):
		if len(r) > 2:
			r.sort()
			if r[-2][0] == r[-3][0]:
				l[i] = '?'
				continue
		l[i] = (r[-1][1], r[-2][1])
	print('\n'.join(map(' '.join, l)))
main()


from collections import deque
(n, m) = tuple(map(int, input().split()))
parti = [deque() for i in range(m)]
for i in range(n):
	s = input().split()
	name = s[0]
	reg = int(s[1])
	sco = int(s[2])
	if len(parti[reg - 1]) == 0:
		parti[reg - 1].append([name, sco])
	elif len(parti[reg - 1]) == 1:
		if sco < parti[reg - 1][0][1]:
			parti[reg - 1].append([name, sco])
		else:
			parti[reg - 1].appendleft([name, sco])
	elif sco >= parti[reg - 1][0][1]:
		while parti[reg - 1][-1][1] < parti[reg - 1][0][1]:
			parti[reg - 1].pop()
		parti[reg - 1].appendleft([name, sco])
	elif sco >= parti[reg - 1][-1][1]:
		while parti[reg - 1][-1][1] < sco:
			parti[reg - 1].pop()
		parti[reg - 1].append([name, sco])
for i in range(m):
	if len(parti[i]) > 2:
		print('?')
	else:
		print(parti[i][0][0], parti[i][1][0])


def getscore(data):
	return data[2]
(n, m) = input().split(' ')
n = int(n)
m = int(m)
l = list()
for i in range(0, n):
	(name, region, score) = input().split(' ')
	score = int(score)
	l.append((name, region, score))
l.sort(key=getscore, reverse=True)
dic_score = dict()
dic_name = dict()
for i in range(1, m + 1):
	st = str(i)
	dic_score[st] = list()
	dic_name[st] = list()
for i in range(0, n):
	dic_score[l[i][1]].append(l[i][2])
	dic_name[l[i][1]].append(l[i][0])
for j in range(1, m + 1):
	i = str(j)
	if len(dic_score[i]) == 2:
		flag = False
	elif dic_score[i][1] == dic_score[i][2]:
		flag = True
	else:
		flag = False
	if flag:
		print('?')
	else:
		print(dic_name[i][0], dic_name[i][1])


(n, m) = list(map(int, input().split()))
d = {}
for i in range(1, m + 1):
	d[i] = []
for i in range(n):
	(a, b, c) = input().split()
	a = str(a)
	b = int(b)
	c = int(c)
	d[b].append([c, a])
for i in range(1, m + 1):
	a = d[i]
	a.sort(reverse=True)
	if len(a) > 2 and a[1][0] == a[2][0]:
		print('?')
	else:
		print(a[0][1], a[1][1])


namelist = [['', '', ''] for i in range(100005)]
scorelist = [[-1, -1, -1] for i in range(100005)]

def enroll(recod):
	name = recod[0]
	region = int(recod[1])
	score = int(recod[2])
	for i in range(3):
		if score > scorelist[region][i]:
			t = name
			name = namelist[region][i]
			namelist[region][i] = t
			t = score
			score = scorelist[region][i]
			scorelist[region][i] = t
ll = input().split()
n = int(ll[0])
m = int(ll[1])
for i in range(n):
	enroll(input().split())
for i in range(1, m + 1):
	if scorelist[i][1] != scorelist[i][2]:
		print('%s %s' % (namelist[i][0], namelist[i][1]))
	else:
		print('?')


read_ints = lambda : list(map(int, input().split()))
(n, m) = read_ints()
R = [[] for _ in range(m)]
for i in range(n):
	(n, r, s) = input().split()
	r = int(r)
	s = int(s)
	R[r - 1].append((s, n))
for r in R:
	r.sort(reverse=True)
	if len(r) > 2:
		if r[1][0] == r[2][0]:
			print('?')
		else:
			print('%s %s' % (r[0][1], r[1][1]))
	else:
		print('%s %s' % (r[0][1], r[1][1]))


(n, m) = map(int, input().split())
data = [[] for i in range(m)]
for i in range(n):
	(na, reg, b) = input().split()
	data[int(reg) - 1].append([int(b), na])
for i in range(m):
	data[i] = sorted(data[i])[::-1]
for i in range(m):
	if len(data[i]) == 2:
		print(data[i][0][1], data[i][1][1])
	elif data[i][1][0] == data[i][2][0]:
		print('?')
	else:
		print(data[i][0][1], data[i][1][1])


(n, m) = map(int, input().split())
regions = [[] for i in range(m)]
for i in range(n):
	(name, region, score) = input().split()
	region = int(region)
	score = int(score)
	regions[region - 1] += [(score, name)]
for i in range(m):
	regions[i] = sorted(regions[i])
for i in range(m):
	if len(regions[i]) > 2 and regions[i][-2][0] == regions[i][-3][0]:
		print('?')
	else:
		print(regions[i][-1][1] + ' ' + regions[i][-2][1])


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
ans = [None] * (m + 1)
for i in range(m + 1):
	ans[i] = [None] * 801
for i in range(n):
	(name, region, score) = stdin.readline().split()
	region = int(region)
	score = int(score)
	if ans[region][score] == None:
		ans[region][score] = [name]
	else:
		ans[region][score].append(name)
for i in range(1, m + 1):
	a = []
	rem = 2
	for j in range(800, -1, -1):
		if rem == 0:
			break
		if ans[i][j] != None:
			if rem >= len(ans[i][j]):
				for k in ans[i][j]:
					a.append(k)
				rem -= len(ans[i][j])
			else:
				a = ['?']
				break
	if len(a) == 2:
		stdout.write(str(a[0]) + ' ' + str(a[1]) + '\n')
	else:
		stdout.write('?\n')


import heapq
(n, m) = [int(i) for i in input().split()]
l = [[] for i in range(m)]
for i in range(n):
	(name, region, score) = input().split()
	region = int(region)
	score = int(score)
	heapq.heappush(l[region - 1], (800 - score, name))
for i in range(m):
	d1 = heapq.heappop(l[i])
	d2 = heapq.heappop(l[i])
	if len(l[i]) == 0:
		print(d1[1], d2[1])
	else:
		d3 = heapq.heappop(l[i])
		if d2[0] == d3[0]:
			print('?')
		else:
			print(d1[1], d2[1])


import random, math
from copy import deepcopy as dc

class student:

	def __init__(self, name, reg, score):
		self.name = name
		self.reg = reg
		self.score = score

def input_test():
	(n, m) = map(int, input().strip().split(' '))
	top3 = [[] for i in range(m + 1)]
	for i in range(n):
		(na, r, s) = map(str, input().strip().split(' '))
		r = int(r)
		s = int(s)
		obj = student(na, r, s)
		if len(top3[r]) == 0:
			top3[r].append(obj)
		elif len(top3[r]) < 3:
			top3[r].append(obj)
			top3[r].sort(key=lambda x: x.score, reverse=True)
		elif top3[r][0].score < s:
			top3[r][2] = top3[r][1]
			top3[r][1] = top3[r][0]
			top3[r][0] = obj
		elif top3[r][1].score < s and (not top3[r][0].name == obj.name):
			top3[r][2] = top3[r][1]
			top3[r][1] = obj
		elif top3[r][2].score < s and (not (top3[r][0].name == obj.name or top3[r][2].name == obj.name)):
			top3[r][2] = obj
	for i in range(1, m + 1):
		if len(top3[i]) > 2 and (top3[i][0].score == top3[i][2].score or top3[i][1].score == top3[i][2].score):
			print('?')
		else:
			print(top3[i][0].name + ' ' + top3[i][1].name)
input_test()


(n, m) = map(int, input().split())
d = {}
for _ in range(n):
	(i, r, b) = input().split()
	r = int(r)
	b = int(b)
	d.setdefault(r, []).append((b, i))
ans = []
for x in sorted(d):
	t = sorted(d[x])[::-1]
	if len(t) > 2 and t[1][0] == t[2][0]:
		ans += ['?']
	else:
		ans += [' '.join([t[0][1], t[1][1]])]
print('\n'.join(ans))


(p, r) = map(int, input().split())
regions = [[] for i in range(r)]
for i in range(p):
	(name, reg, score) = map(str, input().split())
	reg = int(reg) - 1
	score = int(score)
	regions[reg].append([score, name])
for i in regions:
	i.sort()
	if len(i) > 2:
		if i[-1][0] == i[-2][0] == i[-3][0] or i[-2][0] == i[-3][0]:
			print('?')
		else:
			print(i[-1][1], i[-2][1])
	else:
		print(i[-1][1], i[-2][1])


(n, m) = input().split()
(n, m) = (int(n), int(m))
score = [[] for i in range(m)]
for i in range(n):
	(tem1, tem2, tem3) = input().split()
	tem2 = int(tem2)
	score[tem2 - 1].append([tem1, int(tem3)])
for i in range(m):
	score[i].sort(key=lambda x: x[1], reverse=True)
for i in range(m):
	if len(score[i]) <= 2 or score[i][1][1] != score[i][2][1]:
		print(score[i][0][0], score[i][1][0])
	else:
		print('?')


from sys import *
inp = lambda : stdin.readline()

def main():
	(n, m) = [int(i) for i in inp().split()]
	d = {}
	for i in range(1, n + 1):
		d[i] = []
	for i in range(n):
		(a, b, c) = [i for i in inp().split()]
		(b, c) = (int(b), int(c))
		d[b].append((c, a))
	for i in range(1, m + 1):
		d[i] = sorted(d[i], key=lambda x: -x[0])
		if len(d[i]) < 3:
			print(d[i][0][1], d[i][1][1])
		else:
			(b, c) = (d[i][1][0], d[i][2][0])
			if b == c:
				print('?')
			else:
				print(d[i][0][1], d[i][1][1])
main()


string = input().split()
n = int(string[0])
m = int(string[1])
regions = []
for i in range(m + 1):
	regions.append([])
for i in range(n):
	string = input().split()
	reg = int(string[1])
	name = string[0]
	points = int(string[2])
	regions[reg].append((name, points))
for i in range(1, m + 1):
	regions[i].sort(key=lambda x: x[1], reverse=True)
	if len(regions[i]) == 2:
		print(regions[i][0][0], regions[i][1][0])
	elif regions[i][1][1] == regions[i][2][1]:
		print('?')
	else:
		print(regions[i][0][0], regions[i][1][0])


def main():
	(n, m) = map(int, input().split())
	d = {}
	for i in range(1, m + 1):
		d[i] = []
	for i in range(n):
		(a, b, c) = input().split()
		(b, c) = map(int, (b, c))
		d[b] += [(c, a)]
	for i in range(1, m + 1):
		t = sorted(d[i])[::-1]
		print('?' if len(t) > 2 and t[1][0] == t[2][0] else t[0][1] + ' ' + t[1][1])
main()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
regions = {}
for student in range(n):
	(name, region, score) = input().split()
	if not regions.get(int(region)):
		regions[int(region)] = []
	regions[int(region)].append([int(score), name])
for i in regions:
	regions[i].sort(reverse=True)
for r in range(1, m + 1):
	lst = regions[r]
	if len(lst) == 2:
		print(lst[0][1], lst[1][1])
	elif lst[2][0] == lst[1][0]:
		print('?')
	else:
		print(lst[0][1], lst[1][1])


(n, m) = map(int, input().split(' '))
b = {}
pb = {}
ppb = {}
for i in range(n):
	curline = input().split(' ')
	name = curline[0]
	(com, ball) = map(int, curline[1:3])
	x = (name, ball)
	if com in b:
		if x[1] > b[com][1]:
			(b[com], x) = (x, b[com])
		if com in pb:
			if x[1] > pb[com][1]:
				(pb[com], x) = (x, pb[com])
			if com in ppb:
				if x[1] > ppb[com][1]:
					(ppb[com], x) = (x, ppb[com])
			else:
				ppb[com] = x
		else:
			pb[com] = x
	else:
		b[com] = x
for com in range(1, m + 1):
	if com in ppb and ppb[com][1] == pb[com][1]:
		print('?')
	else:
		print(b[com][0], pb[com][0])


(n, m) = map(int, input().split())
dic = {i + 1: [] for i in range(m)}
for i in range(n):
	a = [i for i in input().split()]
	a[1] = int(a[1])
	a[2] = int(a[2])
	a.reverse()
	dic[a[1]].append(a)
for i in range(1, m + 1):
	dic[i].sort(reverse=True)
	if len(dic[i]) > 2:
		if dic[i][1][0] == dic[i][2][0]:
			print('?')
		else:
			print(dic[i][0][2], dic[i][1][2])
	else:
		print(dic[i][0][2], dic[i][1][2])


def main():
	(n, m) = map(int, input().strip().split())
	r = [[] for _ in range(m)]
	for _ in range(n):
		(name, region, score) = input().strip().split()
		region = int(region)
		score = int(score)
		r[region - 1].append((name, score))
	for i in range(m):
		p = sorted(r[i], key=lambda x: x[1], reverse=True)
		if len(p) == 2 or p[0][1] >= p[1][1] > p[2][1]:
			print('{} {}'.format(p[0][0], p[1][0]))
		else:
			print('?')
main()


import sys
(n, m) = map(int, sys.stdin.readline().split())
regions = [[] for i in range(m + 1)]
for i in range(n):
	(fam, reg, val) = sys.stdin.readline().split()
	regions[int(reg)].append((int(val), fam))
for i in range(1, m + 1):
	regions[i].sort(key=lambda x: x[0])
	if len(regions[i]) > 2 and regions[i][-2][0] == regions[i][-3][0]:
		sys.stdout.write('?' + '\n')
	else:
		sys.stdout.write(' '.join([regions[i][-1][1], regions[i][-2][1]]) + '\n')


(n, m) = [int(i) for i in input().split()]
regls = [[] for i in range(m)]
for i in range(n):
	(name, reg, mark) = input().split()
	reg = int(reg) - 1
	mark = int(mark)
	regls[reg].append((name, mark))
for i in range(m):
	regls[i] = sorted(regls[i], key=lambda x: x[1], reverse=True)
	if len(regls[i]) > 2 and regls[i][1][1] == regls[i][2][1]:
		print('?')
	else:
		print(regls[i][0][0], regls[i][1][0])


(n, m) = map(int, input().split(' '))
c = {}
for i in range(n):
	line = input().split()
	(line[1], line[2]) = (int(line[1]), int(line[2]))
	if line[1] not in c:
		c[line[1]] = []
	c[line[1]].append((line[2], line[0]))
for i in range(1, m + 1):
	c[i].sort(reverse=True)
	if len(c[i]) > 2 and c[i][1][0] == c[i][2][0]:
		print('?')
	else:
		print(c[i][0][1], c[i][1][1])


from sys import stdin
(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(map(str, stdin.readline().split())))
	arr[i][1] = int(arr[i][1])
	arr[i][2] = int(arr[i][2])
regions = {}
for i in range(1, m + 1):
	regions[i] = []
for i in arr:
	regions[i[1]].append([i[2], i[0]])
for i in regions:
	regions[i] = sorted(regions[i], reverse=True)
for i in range(1, m + 1):
	flag = True
	if len(regions[i]) > 2:
		if regions[i][2][0] == regions[i][1][0]:
			print('?')
			flag = False
	if flag:
		print(regions[i][0][1], regions[i][1][1])


(n, m) = (int(z) for z in input().split())
Par = [850] * m
Res = dict()
r = dict()
fail = [0] * m
for i in range(1, m + 1):
	r[i] = []
for i in range(n):
	s = [z for z in input().split()]
	Res[s[0]] = int(s[2])
	if len(r[int(s[1])]) < 2:
		r[int(s[1])].append(s[0])
		if Par[int(s[1]) - 1] > int(s[2]):
			Par[int(s[1]) - 1] = int(s[2])
	elif Par[int(s[1]) - 1] < int(s[2]):
		if Res[r[int(s[1])][0]] < Res[r[int(s[1])][1]]:
			r[int(s[1])][0] = s[0]
			Par[int(s[1]) - 1] = min(Res[r[int(s[1])][0]], Res[r[int(s[1])][1]])
			fail[int(s[1]) - 1] = 0
		elif Res[r[int(s[1])][0]] > Res[r[int(s[1])][1]]:
			r[int(s[1])][1] = s[0]
			Par[int(s[1]) - 1] = min(Res[r[int(s[1])][0]], Res[r[int(s[1])][1]])
			fail[int(s[1]) - 1] = 0
		else:
			fail[int(s[1]) - 1] = 1
			r[int(s[1])][1] = s[0]
	elif Par[int(s[1]) - 1] == int(s[2]):
		fail[int(s[1]) - 1] = 1
for i in range(1, m + 1):
	if fail[i - 1] == 0:
		print(r[i][0], r[i][1])
	else:
		print('?')


from sys import stdin

def input():
	return stdin.readline()
ans = []
(n, m) = map(int, input().split())
d = {}
r = [[] for i in range(m)]
for i in range(n):
	(a, b, c) = input().split()
	(b, c) = (int(b), int(c))
	d[a] = c
	r[b - 1] += [a]
x = []
for i in range(m):
	x = sorted(r[i], key=lambda x: -d[x])
	if len(x) == 2:
		ans += [x[0] + ' ' + x[1]]
	elif d[x[2]] == d[x[1]]:
		ans += ['?']
	else:
		ans += [x[0] + ' ' + x[1]]
print('\n'.join(ans))


(n, m) = [int(i) for i in input().split()]
team = [{} for i in range(m + 1)]
a = [[] for i in range(m + 1)]
for i in range(n):
	(name, region, score) = input().split()
	(region, score) = (int(region), int(score))
	team[region][name] = score
	a[region].append(score)
for i in range(1, m + 1):
	a[i] = sorted(a[i], reverse=True)
	if len(a[i]) == 2:
		print(' '.join([j for j in team[i]]))
	elif a[i][2] == a[i][1]:
		print('?')
	else:
		ans = sorted(team[i].items(), key=lambda t: t[1], reverse=True)
		print(ans[0][0], ans[1][0])


3

class StdIO:

	def read_int(self):
		return int(self.read_string())

	def read_ints(self, sep=None):
		return [int(i) for i in self.read_strings(sep)]

	def read_float(self):
		return float(self.read_string())

	def read_floats(self, sep=None):
		return [float(i) for i in self.read_strings(sep)]

	def read_string(self):
		return input()

	def read_strings(self, sep=None):
		return self.read_string().split(sep)
io = StdIO()

def main():
	(n, m) = io.read_ints()
	ppl = [list() for i in range(m)]
	for i in range(n):
		(name, reg, score) = io.read_strings()
		reg = int(reg)
		score = int(score)
		reg -= 1
		ppl[reg].append((score, name))
	for reg in range(m):
		ppl[reg].sort(reverse=True)
		team = ppl[reg]
		sca = team[0][0]
		scb = team[1][0]
		scc = team[2][0] if len(team) > 2 else None
		if scc is None or (sca > scc and scb > scc):
			print(team[0][1], team[1][1])
		else:
			print('?')

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
a = [[] for i in range(m)]
b = ['' for i in range(n)]
for i in range(n):
	(b[i], id, s) = input().split()
	a[int(id) - 1].append((-int(s), i))
for i in range(m):
	t = sorted(a[i])
	if len(t) > 2 and t[1][0] == t[2][0]:
		print('?')
	else:
		print(b[t[0][1]], b[t[1][1]])


try:
	while True:
		(n, m) = map(int, input().split())
		d = [[] for i in range(m)]
		for i in range(n):
			(name, region, score) = input().split()
			region = int(region) - 1
			score = int(score)
			d[region].append((score, name))
		for i in range(m):
			ls = d[i]
			ls.sort(reverse=True)
			if len(ls) > 2 and ls[1][0] == ls[2][0]:
				print('?')
			else:
				print(ls[0][1], ls[1][1])
except EOFError:
	pass


def main():
	(n, m) = map(int, input().split())
	l = [[] for _ in range(m)]
	for _ in range(n):
		(s, a, b) = input().split()
		l[int(a) - 1].append((int(b), s))
	for (i, r) in enumerate(l):
		if len(r) > 2:
			r.sort()
			if r[-2][0] == r[-3][0]:
				l[i] = '?'
				continue
		l[i] = (r[-1][1], r[-2][1])
	print('\n'.join(map(' '.join, l)))
main()


(student_number, regions) = map(int, input().split())
competiton_description = dict()
for _ in range(student_number):
	(surname, region, score) = input().split()
	if int(region) not in competiton_description:
		competiton_description[int(region)] = [[int(score), surname]]
	else:
		competiton_description[int(region)].append([int(score), surname])
for (key, value) in sorted(competiton_description.items()):
	value.sort(key=lambda s: (-s[0], s[1]))
	if len(value) > 2 and value[1][0] == value[2][0]:
		print('?')
	else:
		print(value[0][1], value[1][1])


def sortByScore(elem):
	return int(elem[2])
s = input()
s = s.split()
n = int(s[0])
m = int(s[1])
x = [0] * m
for i in range(m):
	x[i] = []
for i in range(n):
	s = input()
	s = s.split()
	x[int(s[1]) - 1].append(s)
for i in range(m):
	x[i].sort(key=sortByScore, reverse=True)
	if len(x[i]) > 2:
		if x[i][1][2] != x[i][2][2]:
			print(x[i][0][0], x[i][1][0])
		else:
			print('?')
	else:
		print(x[i][0][0], x[i][1][0])


(n, m) = [int(x) for x in input().split()]
reg = []
for i in range(m + 1):
	reg.append([])
for i in range(n):
	(s, r, v) = [x for x in input().split()]
	reg[int(r)].append([s, int(v)])
for i in range(1, m + 1):
	reg[i] = sorted(reg[i], key=lambda x: x[1], reverse=True)
	if len(reg[i]) >= 3:
		if reg[i][1][1] == reg[i][2][1]:
			print('?')
		else:
			print(reg[i][0][0], reg[i][1][0])
	else:
		print(reg[i][0][0], reg[i][1][0])


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
from fractions import *

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, m) = value()
d = defaultdict(list)
for i in range(n):
	(name, r, sc) = input().split()
	d[int(r)].append((int(sc), name))
for i in range(1, m + 1):
	if len(d[i]) == 2:
		print(d[i][0][1], d[i][1][1])
	else:
		t = sorted(d[i])
		if t[-2][0] != t[-3][0]:
			print(t[-1][1], t[-2][1])
		else:
			print('?')


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().rstrip().split())
students = []
regions = {i + 1: [] for i in range(m)}
for i in range(n):
	data = stdin.readline().rstrip().split()
	name = data[0]
	region = int(data[1])
	score = int(data[2])
	regions[region].append([name, score])
for (region, students) in regions.items():
	winners = sorted(students, key=lambda x: -x[1])
	stdout.write(('?' if len(winners) >= 3 and winners[2][1] == winners[1][1] else winners[0][0] + ' ' + winners[1][0]) + '\n')


(n, m) = map(int, input().split())
l = [[] for i in range(m)]
for i in range(n):
	l1 = input().split()
	team = int(l1[1]) - 1
	l[team].append([int(l1[2]), l1[0]])
for i in range(m):
	a = list(sorted(l[i]))[::-1]
	if len(a) == 2:
		print(a[0][1], a[1][1])
	elif a[1][0] == a[2][0]:
		print('?')
	else:
		print(a[0][1], a[1][1])


(n, m) = list(map(int, input().split()))
a = []
for i in range(m):
	a.append([])
for i in range(n):
	(s, c, b) = input().split()
	c = int(c)
	b = int(b)
	a[c - 1].append([-b, s])
for i in range(m):
	a[i].sort()
	if len(a[i]) == 2:
		print(a[i][0][1], a[i][1][1])
	else:
		aa = a[i][1][0]
		bb = a[i][2][0]
		if aa == bb:
			print('?')
		else:
			print(a[i][0][1], a[i][1][1])


import sys
(n, m) = [int(x) for x in input().split()]
A = [[] for i in range(m)]
for line in sys.stdin:
	(name, region, result) = line.split()
	(region, result) = (int(region) - 1, int(result))
	A[region].append((result, name))
for a in A:
	a.sort()
	if len(a) > 2 and a[-2][0] == a[-3][0]:
		sys.stdout.write('?\n')
	else:
		sys.stdout.write(a[-2][1] + ' ' + a[-1][1] + '\n')


import operator

class Person:
	name = ' '
	score = 0
(n, m) = map(int, input().split(' '))
L = []
for i in range(0, m + 1):
	L.append([])
for i in range(0, n):
	(sname, grp, sc) = input().split(' ')
	x = Person()
	x.name = sname
	x.score = int(sc)
	L[int(grp)].append(x)
for i in range(1, m + 1):
	L[i] = sorted(L[i], key=operator.attrgetter('score'), reverse=True)
	if len(L[i]) >= 3:
		if L[i][0].score == L[i][1].score and L[i][1].score == L[i][2].score:
			print('?')
		elif L[i][1].score == L[i][2].score:
			print('?')
		else:
			print(L[i][0].name + ' ' + L[i][1].name)
	else:
		print(L[i][0].name + ' ' + L[i][1].name)


(n, m) = map(int, input().split(' '))
dic = {}
for i in range(n):
	(s, r, p) = input().split(' ')
	if r in dic:
		dic[r].append((int(p), s))
	else:
		dic[r] = []
		dic[r].append((int(p), s))
for i in range(1, m + 1):
	arr = dic[str(i)]
	arr = sorted(arr, reverse=True)
	flag = 0
	if len(arr) == 2:
		flag = 1
		arr = arr[:2]
	else:
		flag = 2
		arr = arr[:3]
	b = [_ for (x, _) in arr]
	scores = [x for (x, _) in arr]
	if flag == 1:
		print(b[0], b[1])
	elif flag == 2:
		if scores[0] == scores[1]:
			if scores[1] != scores[2]:
				print(b[0], b[1])
			else:
				print('?')
		elif scores[1] == scores[2]:
			print('?')
		else:
			print(b[0], b[1])


from operator import itemgetter

class CodeforcesTask659BSolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.parts = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		for x in range(self.n_m[0]):
			self.parts.append(input().split(' '))

	def process_task(self):
		results = []
		region_scores = [[] for x in range(self.n_m[1])]
		for part in self.parts:
			region_scores[int(part[1]) - 1].append((part[0], int(part[2])))
		for region in region_scores:
			if len(region) < 3:
				results.append('{0} {1}'.format(region[0][0], region[1][0]))
			else:
				region.sort(key=itemgetter(1), reverse=True)
				if region[2][1] == region[1][1]:
					results.append('?')
				else:
					results.append('{0} {1}'.format(region[0][0], region[1][0]))
		self.result = '\n'.join(results)

	def get_result(self):
		return self.result
Solution = CodeforcesTask659BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


class shkolnik:
	ball = 0
(n, m) = map(int, input().split())
a = []

def ballsort(x):
	return x.ball
for i in range(m + 1):
	a.append([])
for i in range(n):
	c = shkolnik()
	(c.family, reg, c.ball) = input().split()
	c.ball = int(c.ball)
	a[int(reg)].append(c)
for i in range(1, m + 1):
	a[i].sort(key=ballsort)
for i in range(1, m + 1):
	if len(a[i]) > 2 and a[i][-2].ball == a[i][-3].ball:
		print('?')
	else:
		print(a[i][-1].family, a[i][-2].family)


def cmp(x):
	return x[1]
(n, m) = map(int, input().split())
q = [[] for i in range(m)]
for i in range(n):
	(name, r, b) = input().split()
	q[int(r) - 1].append([name, int(b)])
for i in q:
	i = sorted(i, key=cmp)
	if len(i) == 2:
		print(i[-1][0], i[-2][0])
	elif i[-1][1] == i[-2][1] == i[-3][1] or i[-2][1] == i[-3][1]:
		print('?')
	else:
		print(i[-1][0], i[-2][0])


(n, m) = map(int, input().split())
a = [[] for i in range(m + 1)]
for i in range(n):
	b = input().split()
	a[int(b[1])] += [(int(b[2]), b[0])]
for i in range(1, m + 1):
	a[i].sort(key=lambda x: x[0], reverse=1)
	t = [it[0] for it in a[i][:3]]
	if len(a[i]) == 2 or t[1] != t[2]:
		print(a[i][0][1], a[i][1][1])
	else:
		print('?')


II = lambda : map(int, input().split())
(n, m) = II()
reg = [list() for _ in range(m)]
for _ in range(n):
	(name, region, score) = input().split()
	reg[int(region) - 1].append((int(score), name))
for l in map(sorted, reg):
	if len(l) > 2 and l[-2][0] == l[-3][0]:
		print('?')
	else:
		print(l[-1][1], l[-2][1])


(n, m) = map(int, input().split())
d = [[] for i in range(m + 1)]
for i in range(n):
	(a, b, c) = input().split()
	d[int(b)].append([int(c), a])
for i in range(1, m + 1):
	d[i] = sorted(d[i], key=lambda x: -x[0])
	if len(d[i]) <= 2:
		print(d[i][0][1] + ' ' + d[i][1][1])
	elif d[i][1][0] == d[i][2][0]:
		print('?')
	else:
		print(d[i][0][1] + ' ' + d[i][1][1])


(n, m) = map(int, input().split())
l = [[] for i in range(m)]
for i in range(n):
	a = input().split()
	(x, y) = (int(a[1]), int(a[2]))
	l[x - 1].append([y, a[0]])
for i in range(m):
	l[i].sort()
	if len(l[i]) > 2:
		if l[i][-2][0] == l[i][-3][0]:
			print('?')
		else:
			print(l[i][-1][1] + ' ' + l[i][-2][1])
	else:
		print(l[i][-1][1] + ' ' + l[i][-2][1])


(a, b) = map(int, input().split())
d = {}
for i in range(a):
	f = list(input().split())
	if int(f[1]) in d:
		d[int(f[1])].append((int(f[2]), f[0]))
	else:
		d[int(f[1])] = [(int(f[2]), f[0])]
for i in d:
	d[i].sort()
	d[i].reverse()
for i in range(1, b + 1):
	if len(d[i]) > 2 and d[i][2][0] == d[i][1][0]:
		print('?')
	else:
		print(d[i][0][1], d[i][1][1])


from sys import stdin, stdout
(a, b) = map(int, stdin.readline().split())
d = {}
for i in range(1, b + 1):
	d[i] = []
for _ in ' ' * a:
	(x, y, z) = stdin.readline().split()
	y = int(y)
	z = int(z)
	d[y].append([z, x])
ans = ''
for i in d:
	d[i].sort(reverse=True)
	if len(d[i]) > 2 and d[i][1][0] == d[i][2][0]:
		ans += '?'
	else:
		ans += d[i][0][1] + ' ' + d[i][1][1]
	ans += '\n'
stdout.write(ans)


(n, m) = list(map(int, input().split()))
arr = []
for _ in range(n):
	arr.append(input().split())
arr.sort(key=lambda x: (int(x[1]), -int(x[2])))
am = [0] * m
for i in range(n):
	am[int(arr[i][1]) - 1] += 1
j = 0
for i in range(m):
	if am[i] == 2:
		print(arr[j][0], arr[j + 1][0])
	if am[i] > 2:
		if arr[j][2] == arr[j + 1][2] == arr[j + 2][2] or arr[j + 1][2] == arr[j + 2][2]:
			print('?')
		else:
			print(arr[j][0], arr[j + 1][0])
	j += am[i]


s = input().split()
n = int(s[0])
m = int(s[1])
mas = []
for i in range(n):
	mas.append(input().split())
for i in range(n):
	mas[i][1] = int(mas[i][1])
	mas[i][2] = int(mas[i][2])
	mas[i][0] = str(mas[i][0])

def getKey(item):
	return item[1]
mas1 = sorted(mas, key=getKey)

def UpperBound(A, key):
	left = -1
	right = len(A)
	while right > left + 1:
		middle = (left + right) // 2
		if A[middle][1] > key:
			right = middle
		else:
			left = middle
	return right

def getKey(item):
	return item[2]
result = []
value = 0
for i in range(n):
	if value != n:
		right = UpperBound(mas1, mas1[value][1])
		res = right - value
		mas2 = sorted(mas1[value:right], key=getKey)
		if res == 2:
			result.append(mas2[res - 1][0] + ' ' + mas2[res - 2][0])
		elif mas2[res - 2][2] == mas2[res - 3][2]:
			result.append('?')
		else:
			result.append(mas2[res - 1][0] + ' ' + mas2[res - 2][0])
		value = right
for i in range(m):
	print(result[i])


import sys
d = dict()
(n, m) = map(int, sys.stdin.readline().split())
for i in range(n):
	s = input()
	s1 = s.split()
	group = int(s1[1])
	score = int(s1[2])
	if group not in d.keys():
		d[group] = dict()
	if score in d[group].keys():
		d[group][score].append(s1[0])
	else:
		d[group][score] = [s1[0]]
for i in range(1, m + 1):
	boolean = 0
	ma = max(d[i].keys())
	if len(d[i][ma]) == 2:
		print(d[i][ma][0], d[i][ma][1])
		boolean = 1
	elif len(d[i][ma]) == 1:
		first = d[i][ma][0]
		a = d[i].pop(ma)
		ma = max(d[i].keys())
		if len(d[i][ma]) == 1:
			print(first, d[i][ma][0])
			boolean = 1
	if boolean == 0:
		print('?')


from collections import defaultdict
(n, m) = list(map(int, input().split()))
data = defaultdict(dict)
for _ in range(n):
	(name, region, score) = input().split()
	region = int(region)
	score = int(score)
	if region not in data:
		data[region] = defaultdict(list)
	data[region][score].append(name)
for r in range(1, m + 1):
	scores = data[r]
	score_list = list(scores)
	score_list.sort()
	best = score_list[-1]
	if len(scores[best]) > 2:
		print('?')
	elif len(scores[best]) == 1:
		second = score_list[-2]
		if len(scores[second]) >= 2:
			print('?')
		else:
			name1 = scores[best][0]
			name2 = scores[second][0]
			print(name1, name2)
	else:
		print(' '.join(scores[best]))


(n, m) = map(int, input().split())
flst = [[] for i in range(m)]
lst = []
notallowed = []
for i in range(n):
	lst.append(list(map(str, input().split())))
for i in range(n):
	a = int(lst[i][1]) - 1
	if len(flst[a]) < 2:
		flst[a].append([lst[i][0], int(lst[i][2])])
	elif flst[a][0][1] > flst[a][1][1]:
		if flst[a][1][1] > int(lst[i][2]):
			continue
		elif flst[a][1][1] < int(lst[i][2]):
			flst[a][1] = [lst[i][0], int(lst[i][2])]
		else:
			l = flst[a].copy()
			notallowed.append(l)
	elif flst[a][0][1] < flst[a][1][1]:
		if flst[a][0][1] > int(lst[i][2]):
			continue
		elif flst[a][0][1] < int(lst[i][2]):
			flst[a][0] = [lst[i][0], int(lst[i][2])]
		else:
			l = flst[a].copy()
			notallowed.append(l)
	elif flst[a][0][1] > int(lst[i][2]):
		continue
	elif flst[a][0][1] == int(lst[i][2]):
		l = flst[a].copy()
		notallowed.append(l)
	else:
		flst[a][1] = [lst[i][0], int(lst[i][2])]
		l = flst[a].copy()
		notallowed.append(l)
for item in flst:
	if item in notallowed:
		print('?')
	else:
		print(item[0][0], item[1][0])


(n, m) = [int(x) for x in input().split()]
regions = []
for i in range(m):
	regions.append([])
for i in range(n):
	(name, rid, score) = input().split()
	rid = int(rid) - 1
	score = int(score)
	regions[rid].append((name, score))
for region in regions:
	region.sort(key=lambda x: x[1], reverse=True)
	if len(region) > 2 and region[1][1] == region[2][1]:
		print('?')
	else:
		print(region[0][0], region[1][0])


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().strip().split())
regs = [[] for i in range(m + 1)]
for i in range(n):
	(name, r, p) = stdin.readline().strip().split()
	regs[int(r)].append([int(p), name])
for i in range(1, m + 1):
	regs[i].sort()
	if len(regs[i]) > 2 and regs[i][-3][0] == regs[i][-2][0]:
		stdout.write('?\n')
	else:
		stdout.write('%s %s\n' % (regs[i][-2][1], regs[i][-1][1]))


(n, m) = [int(i) for i in input().split()]
people_in_region = {}
for i in range(n):
	(name, region, score) = [item.strip() for item in input().split()]
	region = int(region)
	score = int(score)
	if not region in people_in_region:
		people_in_region[region] = []
	people_in_region[region].append((score, name))
for region in sorted(people_in_region):
	if len(people_in_region[region]) < 3:
		all_people = people_in_region[region]
		print(all_people[0][1], end=' ')
		print(all_people[1][1])
	else:
		all_people = sorted(people_in_region[region], reverse=True)
		if all_people[1][0] == all_people[2][0]:
			print('?')
		else:
			print(all_people[0][1], end=' ')
			print(all_people[1][1])


from sys import stdin

def input():
	return stdin.readline()
(n, m) = [int(i) for i in input().split()]
data = [[(-1, 'xxx')] for i in range(m)]
for i in range(n):
	(name, region, score) = input().split()
	region = int(region)
	score = int(score)
	data[region - 1].append((score, name))
for i in range(m):
	t = sorted(data[i], reverse=True)
	if t[2][0] != t[0][0] and t[2][0] != t[1][0]:
		print(t[0][1], t[1][1])
	else:
		print('?')


(n, m) = map(int, input().split())
k = []
for i in range(0, m + 1):
	k.append([])
while n:
	n -= 1
	(q, t, s) = input().split()
	k[int(t)].append([q, int(s)])
for i in range(1, len(k)):
	k[i].sort(key=lambda x: -x[1])
	if len(k[i]) < 2:
		print('?')
	elif len(k[i]) > 2 and k[i][1][1] == k[i][2][1]:
		print('?')
	else:
		print(k[i][0][0], k[i][1][0])


(n, m) = map(int, input().split())
a = []
d = {}
for j in range(m):
	a.append([])
for i in range(n):
	x = list(input().split())
	a[int(x[1]) - 1].append(x[0])
	d[x[0]] = int(x[2])
for p in range(m):
	a[p].sort(key=lambda x: d[x], reverse=True)
for k in range(m):
	if len(a[k]) == 2:
		for _ in range(2):
			if _ == 0:
				print(a[k][_], end=' ')
			else:
				print(a[k][_])
	elif d[a[k][0]] == d[a[k][1]] != d[a[k][2]] or d[a[k][1]] != d[a[k][2]]:
		for _ in range(2):
			if _ == 0:
				print(a[k][_], end=' ')
			else:
				print(a[k][_])
	elif d[a[k][1]] == d[a[k][2]]:
		print('?', sep=' ')


def main():
	(N, M) = map(int, input().split())
	x = {}
	for i in range(M):
		x[i + 1] = []
	for j in range(N):
		(a, b, c) = input().split()
		b = int(b)
		c = int(c)
		x[b] += [(c, a)]
	for k in range(M):
		y = sorted(x[k + 1])[::-1]
		if len(y) > 2 and y[1][0] == y[2][0]:
			print('?')
		else:
			print(y[0][1] + ' ' + y[1][1])
main()


(participants, regions) = map(int, input().split())
final_result = {}
for i in range(participants):
	(name, region, score) = input().split()
	if region in final_result:
		final_result[region].append([int(score), name])
	else:
		final_result[region] = [[int(score), name]]
for i in range(1, regions + 1):
	j = str(i)
	if len(final_result[j]) > 2:
		final_result[j].sort()
		if final_result[j][-3][0] == final_result[j][-2][0]:
			print('?')
		else:
			print(final_result[j][-1][1], final_result[j][-2][1])
	else:
		print(final_result[j][1][1], final_result[j][0][1])


def contest(n, m, P):
	D = [[(-1, None), (-1, None), (-1, None)] for _ in range(m)]
	for (n, r, p) in P:
		D_i = D[r - 1]
		d = (p, n)
		if d > D_i[0]:
			D_i[2] = D_i[1]
			D_i[1] = D_i[0]
			D_i[0] = d
		elif d > D_i[1]:
			D_i[2] = D_i[1]
			D_i[1] = d
		elif d > D_i[2]:
			D_i[2] = d
	for i in range(m):
		D_i = D[i]
		if D_i[1][0] == D_i[2][0]:
			yield '?'
		else:
			yield f'{D_i[0][1]} {D_i[1][1]}'

def readp():
	(n, sr, sp) = input().split()
	return (n, int(sr), int(sp))

def main():
	(n, m) = readinti()
	P = [readp() for _ in range(n)]
	print('\n'.join(contest(n, m, P)))
import sys

def readint():
	return int(input())

def readinti():
	return map(int, input().split())

def readintt():
	return tuple(readinti())

def readintl():
	return list(readinti())

def readinttl(k):
	return [readintt() for _ in range(k)]

def readintll(k):
	return [readintl() for _ in range(k)]

def log(*args, **kwargs):
	print(*args, **kwargs, file=sys.stderr)
main()


import time
(n, m) = (int(i) for i in input().split())
a = {}
for i in range(m):
	a[i] = []
for i in range(n):
	(f, r, s) = (i for i in input().split())
	r = int(r) - 1
	a[r].append([f, int(s)])
start = time.time()
ans = []
for i in range(m):
	a[i] = sorted(a[i], key=lambda x: x[1], reverse=True)
	if len(a[i]) > 2 and a[i][1][1] == a[i][2][1]:
		ans.append('?')
	else:
		ans.append(a[i][0][0] + ' ' + a[i][1][0])
for i in range(m):
	print(ans[i])
finish = time.time()


from operator import itemgetter
from collections import defaultdict
(n, m) = map(int, input().split())
dicta = defaultdict(list)
details = []
for i in range(n):
	participant = input().split()
	participant[1] = int(participant[1])
	participant[2] = int(participant[2])
	details.append(participant)
details.sort(key=itemgetter(1, 2))
for j in range(n):
	dicta[details[j][1]].append([details[j][0], details[j][2]])
for key in dicta.keys():
	valu = len(dicta[key])
	if len(dicta[key]) != 2 and dicta[key][valu - 2][1] == dicta[key][valu - 3][1]:
		print('?')
	else:
		print('{} {}'.format(dicta[key][valu - 1][0], dicta[key][valu - 2][0]))


def solve():
	(N, M) = list(map(int, input().split()))
	ds = [[] for _ in range(M)]
	for i in range(N):
		(name, dn, score) = input().split()
		dn = int(dn) - 1
		ds[dn].append((-int(score), name))
	for i in range(M):
		ps = ds[i]
		ps.sort()
		if len(ps) == 2:
			print('%s %s' % (ps[0][1], ps[1][1]))
		elif ps[1][0] == ps[2][0]:
			print('?')
		else:
			print('%s %s' % (ps[0][1], ps[1][1]))

def __starting_point():
	solve()
__starting_point()


nm = list(map(int, input().split()))
largeDict = {}
for i in range(nm[1]):
	largeDict[i + 1] = {}
for i in range(nm[0]):
	tempList = input().split()
	largeDict[int(tempList[1])][tempList[0]] = int(tempList[2])
for i in range(nm[1]):
	aList = []
	newDict = {}
	aList = list(largeDict[i + 1].values())
	aList = sorted(aList)[len(aList) - 2:]
	for h in list(largeDict[i + 1].keys()):
		if largeDict[i + 1][h] in aList:
			newDict[h] = largeDict[i + 1][h]
	largeDict[i + 1] = newDict
	if len(list(largeDict[i + 1].keys())) > 2:
		print('?')
	else:
		print(' '.join(list(largeDict[i + 1].keys())))


(n, m) = map(int, input().split())
xs = [list() for _ in range(m)]
for _ in range(n):
	(f, r, s) = input().split()
	r = int(r) - 1
	s = int(s)
	xs[r].append((s, f))
for x in xs:
	x.sort(key=lambda p: p[0], reverse=True)
	if len(x) == 2 or x[1][0] != x[2][0]:
		print('{} {}'.format(x[0][1], x[1][1]))
	else:
		print('?')


import operator

class Participant:

	def __init__(self, name, point):
		self.name = name
		self.point = point
(n, m) = map(int, input().split())
des = [None] * m
for i in range(m):
	des[i] = []
for i in range(n):
	(name, region, point) = input().split()
	des[int(region) - 1].append(Participant(name, int(point)))
results = ['?'] * m
for i in range(m):
	cur_region = des[i]
	is_ok = False
	if len(cur_region) == 2:
		is_ok = True
	else:
		cur_region.sort(key=operator.attrgetter('point'))
		if cur_region[-2].point != cur_region[-3].point:
			is_ok = True
	if is_ok:
		results[i] = ' '.join([cur_region[-1].name, cur_region[-2].name])
print('\n'.join(results))


(n, m) = map(int, input().split(' '))
regions = [list() for i in range(m)]
for _ in range(n):
	(name, region, score) = input().split(' ')
	(region, score) = (int(region), int(score))
	regions[region - 1].append((score, name))
for i in range(m):
	regions[i].sort()
for i in range(m):
	region = regions[i]
	if len(region) == 2 or region[-3][0] < region[-2][0]:
		print(region[-2][1] + ' ' + region[-1][1])
	else:
		print('?')


__author__ = 'Utena'
import operator
(n, m) = map(int, input().split())

class participant:

	def __init__(self, name, region, score):
		self.name = name
		self.region = int(region)
		self.score = int(score)

	def update(self):
		now.append(self.name)
s = [0] * n
for i in range(n):
	(a, b, c) = input().split()
	s[i] = participant(a, b, c)
s = sorted(s, key=operator.attrgetter('score'), reverse=1)
s = sorted(s, key=operator.attrgetter('region'), reverse=0)
ans = []
now = []
j = 1
cnt = 0
for i in range(n):
	if s[i].region == j:
		if cnt == 1:
			if i == n - 1:
				s[i].update()
			elif s[i + 1].region != s[i].region or s[i + 1].score != s[i].score:
				s[i].update()
			else:
				now = ['?']
			ans.append(now)
			now = []
			j += 1
			cnt = 0
		elif cnt == 0:
			s[i].update()
			cnt += 1
for i in range(m):
	print(' '.join(ans[i]))


(n, m) = map(int, input().split())
b = [[0] * 3 for i in range(n)]
for i in range(n):
	(b[i][2], b[i][0], b[i][1]) = map(str, input().split())
	b[i][0] = int(b[i][0])
	b[i][1] = int(b[i][1])
b.sort()
j = 0
for i in range(m):
	k = 0
	while j < n and b[j][0] == i + 1:
		k += 1
		j += 1
	if k > 2 and b[j - 2][1] == b[j - 3][1]:
		print('?')
	elif k > 0:
		print(b[j - 1][2] + ' ' + b[j - 2][2])


from sys import stdin as Si
from collections import defaultdict as dt
from operator import itemgetter as ig
(n, m) = map(int, Si.readline().split())
h = dt(dict)
for i in range(n):
	(s, r, p) = map(str, Si.readline().split())
	(r, p) = map(int, (r, p))
	if p in h[r]:
		h[r][p] += [s]
	else:
		h[r][p] = [s]
for da in h:
	d = sorted(h[da].items(), key=ig(0), reverse=True)
	(ns, i) = ([], 0)
	while len(ns) < 2:
		if len(d[i][1]) + len(ns) >= 3:
			ns = '?'
			break
		else:
			ns += d[i][1][:2 - len(ns)]
		i += 1
		if i >= len(d):
			break
	print(' '.join(ns))


(n, m) = map(int, input().split())
a = [[] for i in range(m + 1)]
for i in range(n):
	(e, b, c) = input().split()
	b = int(b)
	c = int(c)
	a[b].append([c, e])
for i in range(1, m + 1):
	a[i].sort(reverse=True)
	if len(a[i]) == 2:
		print(a[i][0][-1] + ' ' + a[i][1][-1])
	elif a[i][1][0] == a[i][2][0]:
		print('?')
	else:
		print(a[i][0][-1] + ' ' + a[i][1][-1])


(n, m) = [int(i) for i in input().split()]
l = [[] for i in range(m)]
for i in range(n):
	a = input().split()
	(name, region, score) = (a[0], int(a[1]), int(a[2]))
	l[region - 1].append([name, score])
for i in range(m):
	li = l[i]
	li.sort(key=lambda x: x[1], reverse=True)
	if len(li) == 2:
		print(li[0][0], li[1][0])
	elif li[1][1] == li[2][1]:
		print('?')
	else:
		print(li[0][0], li[1][0])


[n, m] = [int(i) for i in input().split()]
name = [[] for i in range(m)]
for i in range(n):
	(name1, region, score) = input().split()
	name[int(region) - 1].append((name1, int(score)))
for i in range(m):
	t = sorted(name[i], key=lambda x: x[1], reverse=True)
	if len(t) > 2 and t[1][1] == t[2][1]:
		print('?')
	else:
		print(t[0][0], t[1][0])


s = input().split()
n = int(s[0])
m = s[1]
teams = {}
for _ in range(0, n):
	p = input().split()
	name = p[0]
	reg = int(p[1])
	score = int(p[2])
	if reg not in teams:
		teams[reg] = []
	teams[reg].append({'name': name, 'score': score})
for team in teams.values():
	team.sort(key=lambda t: t['score'], reverse=True)
	if len(team) <= 2 or team[1]['score'] != team[2]['score']:
		print(team[0]['name'], team[1]['name'])
	else:
		print('?')


(n, m) = (int(i) for i in input().split())
regions = [[] for i in range(n)]
for i in range(n):
	s = input()
	name = s[:s.find(' ')]
	region = int(s[s.find(' ') + 1:s.rfind(' ')]) - 1
	ball = int(s[s.rfind(' ') + 1:])
	regions[region].append([ball, name])
for i in range(m):
	regions[i].sort()
	if len(regions[i]) == 2 or regions[i][-2][0] != regions[i][-3][0]:
		print(regions[i][-1][1], regions[i][-2][1])
	else:
		print('?')


(n, m) = [int(i) for i in input().split()]
l = [[] for i in range(m)]
for _ in range(n):
	(name, region, score) = input().split()
	(region, score) = (int(region) - 1, int(score))
	l[region].append((score, name))
for i in l:
	i.sort(reverse=True)
for i in l:
	r = []
	temp = i[0][0]
	cnt = 0
	for j in i:
		if j[0] != temp:
			temp = j[0]
			if cnt == 2:
				print(' '.join(r))
				break
		elif cnt == 2:
			print('?')
			break
		cnt += 1
		r.append(j[1])
	else:
		print(' '.join(r))


from collections import defaultdict
(N, M) = map(int, input().split())
teams = defaultdict(list)
for i in range(N):
	(team, m, score) = input().split()
	m = int(m)
	m -= 1
	score = int(score)
	teams[m].append([score, team])
for i in range(M):
	teams[i].sort()
	teams[i].reverse()
	first = teams[i][0][0]
	second = teams[i][1][0]
	if len(teams[i]) <= 2:
		print(teams[i][0][1], teams[i][1][1])
	elif second == teams[i][2][0]:
		print('?')
	else:
		print(teams[i][0][1], teams[i][1][1])


(n, m) = map(int, input().split())
mass = []
for i in range(n):
	mass.append(input().split())
mass.sort(key=lambda x: (int(x[1]), int(x[2])))
tmp = 1
res = []
for i in range(n):
	if int(mass[i][1]) == tmp:
		continue
	else:
		tmp = int(mass[i][1])
		if mass[i - 3][2] == mass[i - 2][2] and mass[i - 3][1] == mass[i - 2][1]:
			res.append('?')
		else:
			res.append(mass[i - 2][0])
			res.append(mass[i - 1][0])
if mass[n - 3][2] == mass[n - 2][2] and mass[n - 3][1] == mass[n - 2][1] and (n > 2):
	res.append('?')
else:
	res.append(mass[n - 2][0])
	res.append(mass[n - 1][0])
i = 0
while True:
	if res[i] == '?':
		print(res[i])
		i += 1
	else:
		print(res[i] + ' ' + res[i + 1])
		i += 2
	if i == len(res):
		break


(n, m) = list(map(int, input().split()))
reg = {}
for i in range(n):
	(s, r, b) = input().split()
	r = int(r)
	b = int(b)
	if r not in reg:
		reg[r] = []
	reg[r].append((b, s))
for i in range(m):
	if len(reg[i + 1]) == 2:
		print(reg[i + 1][0][1], reg[i + 1][1][1])
	else:
		reg[i + 1].sort(reverse=True)
		if reg[i + 1][1][0] == reg[i + 1][2][0]:
			print('?')
		else:
			print(reg[i + 1][0][1], reg[i + 1][1][1])


(n, m) = map(int, input().split())
l = [[] for i in range(m)]
for i in range(n):
	j = input().split()
	j[1] = int(j[1]) - 1
	j[2] = int(j[2])
	l[j[1]].append((j[2], j[0]))
for i in range(m):
	l[i].sort(reverse=1)
	if len(l[i]) > 2 and l[i][1][0] == l[i][2][0]:
		print('?')
	else:
		print(l[i][0][1], l[i][1][1])


l = input()
(n, m) = l.split()
(n, m) = (int(n), int(m))
data = [[]] * m
for i in range(n):
	l = input()
	(name, reg, score) = l.split()
	reg = int(reg) - 1
	score = int(score)
	if data[reg]:
		data[reg].append((score, name))
	else:
		data[reg] = [(score, name)]
for reg in data:
	reg = sorted(reg, reverse=True)
	if len(reg) == 2 or reg[1][0] != reg[2][0]:
		print(reg[0][1], reg[1][1])
	else:
		print('?')


fl = input('')
fl = fl.split(' ')
n = int(fl[0])
m = int(fl[1])
tbl = [[{'n': None, 'v': -1} for i in range(3)] for j in range(m)]
for i in range(n):
	l = input('')
	l = l.split(' ')
	name = l[0]
	score = int(l[2])
	country = int(l[1]) - 1
	tblc = tbl[country]
	if score >= tblc[0]['v']:
		tblc.insert(0, {'n': name, 'v': score})
	elif score >= tblc[1]['v']:
		tblc.insert(1, {'n': name, 'v': score})
	if len(tblc) > 3:
		tblc.pop()
for j in range(m):
	tblc = tbl[j]
	if len(tblc) == 2 or tblc[1]['v'] == tblc[2]['v']:
		print('?')
	else:
		print('%s %s' % (tblc[0]['n'], tblc[1]['n']))


(n, m) = map(int, input().split())
a = {}
for i in range(m):
	a[i + 1] = []
for i in range(n):
	s = input().split()
	a[int(s[1])] += [(int(s[2]), s[0])]
for i in range(m):
	z = sorted(a[i + 1])[::-1]
	print('?' if len(z) > 2 and z[1][0] == z[2][0] else z[0][1] + ' ' + z[1][1])


(n, m) = map(int, input().split())
regions = [[] for i in range(m + 1)]
for i in range(n):
	(fam, reg, val) = input().split()
	regions[int(reg)].append((int(val), fam))
for i in range(1, m + 1):
	regions[i].sort(key=lambda x: x[0])
	if len(regions[i]) > 2 and regions[i][-2][0] == regions[i][-3][0]:
		print('?')
	else:
		print(regions[i][-1][1], regions[i][-2][1])


from operator import itemgetter
from bisect import bisect

def main():
	lst = []
	readint = lambda : [int(x) for x in input().split()]
	(n, m) = readint()
	for i in range(n):
		(name, reg, score) = input().split()
		(reg, score) = (int(reg), int(score))
		lst.append((reg, -score, name))
	lst.sort(key=itemgetter(0, 1))
	keys = [item[0] for item in lst]
	j = 0
	for i in range(m):
		if j + 2 < n:
			if lst[j + 2][0] == lst[j][0] and lst[j + 2][1] == lst[j + 1][1]:
				print('?')
			else:
				print(lst[j][2], lst[j + 1][2])
		else:
			print(lst[j][2], lst[j + 1][2])
		j = bisect(keys, lst[j][0])
main()