#include <bits/stdc++.h>
using namespace std;
struct con {
  string name;
  int point;
  bool operator<(const con& p) const { return point > p.point; }
};
int main() {
  int m, n;
  cin >> n >> m;
  vector<con> v[m];
  for (int i = 0; i < n; i++) {
    con temp;
    int reg;
    cin >> temp.name >> reg >> temp.point;
    v[reg - 1].push_back(temp);
  }
  for (int i = 0; i < m; i++) {
    sort(v[i].begin(), v[i].end());
    if (v[i].size() == 2) {
      cout << v[i][0].name << " " << v[i][1].name << endl;
    } else if (v[i][1].point == v[i][2].point) {
      cout << "?" << endl;
    } else {
      cout << v[i][0].name << " " << v[i][1].name << endl;
    }
  }
  return 0;
}
