#include <bits/stdc++.h>
using namespace std;
int n, m;
struct NODE {
  char name[20];
  int x, y;
} a[100010];
bool cmp(NODE a, NODE b) {
  if (a.x == b.x) return a.y > b.y;
  return a.x < b.x;
}
int main() {
  int i;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s%d%d", a[i].name, &a[i].x, &a[i].y);
  sort(a, a + n, cmp);
  int tmp = 1;
  for (i = 0; i < n; i++) {
    if (a[i].x == tmp) {
      tmp++;
      if (i + 2 > n || a[i + 1].x != a[i + 2].x || a[i + 2].y != a[i + 1].y)
        printf("%s %s\n", a[i].name, a[i + 1].name);
      else
        printf("?\n");
    }
  }
  return 0;
}
