#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::pair;
using std::set;
using std::sort;
using std::string;
using std::vector;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<string, int>>> byreg(m);
  for (int i = 0; i < n; i++) {
    string a;
    int b, c;
    cin >> a >> b >> c;
    byreg[b - 1].push_back(make_pair(a, c));
  }
  for (int i = 0; i < m; i++) {
    sort(byreg[i].begin(), byreg[i].end(),
         [](pair<string, int> &l, pair<string, int> &r) {
           return l.second > r.second;
         });
  }
  for (int i = 0; i < m; i++) {
    if (byreg[i].size() > 2) {
      if (byreg[i][0].second == byreg[i][2].second ||
          byreg[i][1].second == byreg[i][2].second) {
        cout << "?\n";
      } else
        cout << byreg[i][0].first << " " << byreg[i][1].first << "\n";
    } else
      cout << byreg[i][0].first << " " << byreg[i][1].first << "\n";
  }
  return 0;
}
