659B
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3
#define pi acos(-1)
const int maxn=1e3+5;
const int maxx=1e6+5;
set< pair<int,string> >v[11111];
string s[111111];
int n,m,a[111111],b[111111];
int main(){
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>s[i]>>a[i]>>b[i];
v[a[i]].insert( make_pair( -b[i],s[i] ) );
}
for(int i=1; i<=m; i++){
set< pair<int,string> >::iterator it=v[i].begin();
string q=it->second;
int g=it->first;
v[i].erase(it);
it=v[i].begin();
string w=it->second;
int h=it->first;
v[i].erase(it);
if( v[i].empty() ){
cout<<q<<" "<<w<<endl;
continue;
}
it=v[i].begin();
string tr=it->second;
int jk=it->first;
if( jk==h ){
cout<<"?"<<endl;
}
else{
cout<<q<<" "<<w<<endl;
}
}
return 0;
}