#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, vector<pair<int, string>>> ma;
  map<int, vector<pair<int, string>>>::iterator it;
  int x, y;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s >> x >> y;
    ma[x].push_back(make_pair(y, s));
  }
  for (it = ma.begin(); it != ma.end(); it++) {
    sort(it->second.rbegin(), it->second.rend());
    if (it->second.size() == 2) {
      cout << it->second[0].second << " " << it->second[1].second << endl;
    } else if (it->second[1].first == it->second[2].first)
      cout << '?' << endl;
    else
      cout << it->second[0].second << " " << it->second[1].second << endl;
  }
}
