#include <bits/stdc++.h>
using namespace std;
int const MAXN = 1000 * 100 + 10;
vector<pair<int, string> > d[MAXN];
int main() {
  int n, m;
  string sur;
  int r, s;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> sur >> r >> s;
    d[r].push_back(make_pair(s, sur));
  }
  for (int i = 1; i <= m; i++) sort(d[i].begin(), d[i].end());
  for (int i = 1; i <= m; i++) {
    if (d[i].size() > 2) {
      if (d[i][d[i].size() - 2].first > d[i][d[i].size() - 3].first) {
        cout << d[i][d[i].size() - 1].second << " "
             << d[i][d[i].size() - 2].second << "\n";
      } else
        cout << '?' << "\n";
    } else {
      cout << d[i][d[i].size() - 1].second << " "
           << d[i][d[i].size() - 2].second << "\n";
    }
  }
  return 0;
}
