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