#include <bits/stdc++.h>
struct Person {
 public:
  int val, team;
  char name[20];
} person[100005];
bool cmp(Person a, Person b) {
  if (a.team == b.team) return a.val > b.val;
  return a.team < b.team;
}
int out[10005];
int main() {
  int n, m;
  memset(out, 0, sizeof out);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s %d %d", person[i].name, &person[i].team, &person[i].val);
    out[person[i].team]++;
  }
  std::sort(person, person + n, cmp);
  int num = 0;
  for (int i = 0; i < n;) {
    if (out[person[i].team] > 2) {
      if (person[i + 1].val != person[i + 2].val)
        printf("%s %s\n", person[i].name, person[i + 1].name);
      else
        printf("?\n");
    } else {
      printf("%s %s\n", person[i].name, person[i + 1].name);
    }
    i += out[person[i].team];
  }
  return 0;
}
