#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    vector<vector<pair<int, string> > > p(m, vector<pair<int, string> >());
    for (int i = 0; i < n; ++i) {
      pair<int, string> q;
      int r;
      cin >> q.second >> r >> q.first;
      p[r - 1].push_back(q);
    }
    for (int i = 0; i < m; ++i) {
      sort(p[i].begin(), p[i].end());
      int size = (int)p[i].size();
      if (size > 2 && p[i][size - 2].first == p[i][size - 3].first) {
        cout << "?" << endl;
      } else {
        cout << p[i][size - 1].second << " " << p[i][size - 2].second << endl;
      }
    }
  }
  return 0;
}
