#include <bits/stdc++.h>
using namespace std;
template <typename T>
void printvec(vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<priority_queue<pair<int, string> > > lol(m + 1);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int a, b;
    cin >> a >> b;
    lol[a].push(make_pair(b, s));
  }
  for (int i = 1; i <= m; i++) {
    if (lol[i].size() > 2) {
      pair<int, string> f1 = lol[i].top();
      lol[i].pop();
      pair<int, string> f2 = lol[i].top();
      lol[i].pop();
      pair<int, string> f3 = lol[i].top();
      lol[i].pop();
      if (f3.first == f1.first || f3.first == f2.first) {
        cout << "?\n";
        continue;
      } else {
        cout << f1.second << " " << f2.second << "\n";
      }
    } else {
      pair<int, string> f1 = lol[i].top();
      lol[i].pop();
      pair<int, string> f2 = lol[i].top();
      lol[i].pop();
      cout << f1.second << " " << f2.second << "\n";
    }
  }
}
