#include <bits/stdc++.h>
using namespace std;
vector<pair<int, string> > head[10010];
int main() {
  int n, m, team, score;
  char str[100];
  while (cin >> n >> m) {
    for (int i = (1); i <= (m); ++i) head[i].clear();
    for (int i = 0; i < (n); ++i) {
      scanf("%s%d%d", str, &team, &score);
      head[team].push_back(make_pair(score, string(str)));
    }
    for (int i = (1); i <= (m); ++i)
      sort(head[i].begin(), head[i].end()),
          reverse(head[i].begin(), head[i].end());
    for (int i = (1); i <= (m); ++i) {
      int l = 0, ll = 0;
      while (l < head[i].size() && head[i][l].first == head[i][ll].first) l++;
      if (l < 2) {
        ll = l;
        while (l < head[i].size() && head[i][l].first == head[i][ll].first) l++;
      }
      if (l != 2)
        puts("?");
      else {
        cout << head[i][0].second << ' ' << head[i][1].second << endl;
      }
    }
  }
  return 0;
}
