#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
const int inf = 0x3f3f3f3f;
struct Node {
  string name;
  int grade;
  int part;
} node[maxn];
int n, m;
bool cmp(Node a, Node b) {
  if (a.part != b.part)
    return a.part < b.part;
  else
    return a.grade < b.grade;
}
void init() {
  for (int i = 0; i < maxn; i++) {
    node[i].part = 0;
    node[i].grade = 0;
    node[i].name = "";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  init();
  for (int i = 1; i <= n; i++) {
    string temps;
    int grade, part;
    cin >> temps >> part >> grade;
    node[i].name = temps;
    node[i].part = part;
    node[i].grade = grade;
  }
  sort(node + 1, node + n + 1, cmp);
  int num = 0;
  for (int i = 1; i <= n; i++) {
    num++;
    if (i == n || node[i + 1].part != node[i].part) {
      if (num == 1) {
        cout << "?" << endl;
        num = 0;
        continue;
      }
      if (num == 2) {
        cout << node[i].name << " " << node[i - 1].name << endl;
        num = 0;
        continue;
      }
      if (node[i - 1].grade != node[i - 2].grade)
        cout << node[i].name << " " << node[i - 1].name << endl;
      else
        cout << "?" << endl;
      num = 0;
    }
  }
  return 0;
}
