#include <bits/stdc++.h>
using namespace std;
struct Node {
  string name;
  int score;
};
bool cmp(const Node &a, const Node &b) { return a.score > b.score; }
vector<Node> region[100005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int grp;
    Node node;
    cin >> node.name >> grp >> node.score;
    region[grp].push_back(node);
  }
  for (int i = 1; i <= m; ++i) {
    sort(region[i].begin(), region[i].end(), cmp);
    if (region[i].size() == 2) {
      cout << region[i][0].name << " " << region[i][1].name << endl;
    } else {
      if (region[i][2].score == region[i][1].score) {
        cout << "?" << endl;
      } else {
        cout << region[i][0].name << " " << region[i][1].name << endl;
      }
    }
  }
  return 0;
}
