#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, i, j, region, score, x;
  vector<vector<pair<int, string>>> v;
  string s, t, u;
  cin >> n >> m;
  v.assign(m, vector<pair<int, string>>());
  for (i = 0; i < n; i++) {
    cin >> s >> region >> score;
    v[region - 1].push_back({score, s});
  }
  for (i = 0; i < m; i++) {
    sort(v[i].begin(), v[i].end());
    x = 1;
    j = v[i].size() - 2;
    while (v[i][j].first == v[i].back().first && x < 3) {
      x++;
      j--;
      if (j == -1) break;
    }
    if (x == 3) {
      cout << "?" << endl;
      continue;
    }
    if (x == 2) {
      cout << v[i][v[i].size() - 1].second << " "
           << v[i][v[i].size() - 2].second << endl;
      continue;
    }
    if (x == 1) {
      if (j == 0 || v[i][j].first != v[i][j - 1].first) {
        cout << v[i][j + 1].second << " " << v[i][j].second << endl;
        continue;
      } else {
        cout << "?" << endl;
        continue;
      }
    }
  }
  return 0;
}
