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