#include <bits/stdc++.h>
using namespace std;
class ps {
 public:
  int score;
  string s;
};
bool cmp(ps p1, ps p2) {
  if (p1.score >= p2.score)
    return true;
  else
    return false;
}
int main() {
  int n, m;
  string s;
  int region, score;
  scanf("%d %d", &n, &m);
  vector<ps> v[10001];
  ps p;
  for (int i = 0; i < n; i++) {
    cin >> p.s;
    scanf("%d %d", &region, &p.score);
    v[region].push_back(p);
    if (v[region].size() > 3) {
      sort(v[region].begin(), v[region].end(), cmp);
      v[region].pop_back();
    }
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end(), cmp);
  }
  for (int i = 1; i <= m; i++) {
    if (v[i].size() > 2) {
      if (v[i][1].score == v[i][2].score)
        printf("?\n");
      else {
        printf("%s %s\n", v[i][0].s.c_str(), v[i][1].s.c_str());
      }
    } else {
      printf("%s %s\n", v[i][0].s.c_str(), v[i][1].s.c_str());
    }
  }
  return 0;
}
