#include <bits/stdc++.h>
using namespace std;
int main() {
  pair<long long int, string> sn;
  pair<long long int, pair<long long int, string> > rsn;
  pair<long long int, pair<string, string> > rn1n2;
  pair<string, string> n1n2;
  set<pair<long long int, pair<string, string> > > ans;
  set<pair<long long int, pair<long long int, string> > > k;
  set<pair<long long int, pair<long long int, string> > >::iterator it;
  set<pair<long long int, pair<long long int, string> > >::iterator tit;
  set<pair<long long int, pair<long long int, string> > >::iterator lit;
  set<pair<long long int, pair<string, string> > >::iterator ansit;
  long long int n, m;
  cin >> n >> m;
  long long int i, re, score, temp, max1, max2;
  bool flag = 0;
  string name;
  sn = make_pair(-1, "s");
  rsn = make_pair(0, sn);
  k.insert(rsn);
  for (i = 0; i < n; i++) {
    cin >> name >> re >> score;
    sn = make_pair(score, name);
    rsn = make_pair(re, sn);
    k.insert(rsn);
  }
  it = k.begin();
  it++;
  while (it != k.end()) {
    lit = it;
    while (it->first == lit->first && lit != k.end()) lit++;
    lit--;
    flag = 0;
    tit = lit;
    max1 = lit->second.first;
    tit--;
    n1n2 = make_pair(lit->second.second, tit->second.second);
    rn1n2 = make_pair(it->first, n1n2);
    max2 = tit->second.first;
    tit--;
    while (it->first == tit->first && tit != k.begin() && flag == 0) {
      temp = tit->second.first;
      if (temp == max1 || temp == max2) {
        n1n2 = make_pair("?", "0");
        rn1n2 = make_pair(it->first, n1n2);
      }
      tit--;
    }
    ans.insert(rn1n2);
    it = lit;
    it++;
  }
  ansit = ans.begin();
  while (ansit != ans.end()) {
    if (ansit->second.first != "?") {
      cout << ansit->second.first;
      cout << ' ' << ansit->second.second;
    } else
      cout << ansit->second.first;
    cout << endl;
    ansit++;
  }
  return 0;
}
