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