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: interview

Starter code:

Solutions:
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]))


#!/usr/bin/env python3

try:
    while True:
        n, m = list(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



n, m = list(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])









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 = 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])


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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()
#print(finish - start)


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]))
        else:
            if ps[1][0] == ps[2][0]:
                print('?')
            else:
                print('%s %s' % (ps[0][1], ps[1][1]))


def __starting_point():
    solve()

__starting_point()

n, m = list(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])


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())))


class shkolnik():
    ball = 0

n, m = list(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)


n, m = list(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] = list(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])


n,m=list(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)
    #print(ls[i])
    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])


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]))
    #print(value)
    if len(value) > 2 and value[1][0] == value[2][0]:
        print('?')
    else:
        print(value[0][1], value[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])

#!/usr/bin/env python3

read_ints = lambda : list(map(int, input().split()))

def __starting_point():
    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]))

__starting_point()

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])


n, m = list(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('?')



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(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('?')

n, m = list(map(int, input().split(' ')))
b = {}
pb = {}
ppb = {}
for i in range(n):
    curline = input().split(' ')
    name = curline[0]
    com, ball = list(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 = list(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])


from sys import stdin as Si
from collections import defaultdict as dt
from operator import itemgetter as ig 
def __starting_point():
    n,m = list(map(int,Si.readline().split()))
    h = dt(dict)

    for i in range(n):
        s,r,p = list(map(str,Si.readline().split()))
        r,p = list(map(int,(r,p)))
        if p in h[r]:   h[r][p]+=[s]
        else:   h[r][p]=[s]
    for da in h:
        d = sorted(list(h[da].items()),key=ig(0),reverse=True)
        #print(d)
        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))
'''
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.
'''
            
        

__starting_point()

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])