#include <bits/stdc++.h>
using namespace std;
struct node {
  char c[25];
  int n;
  int m;
} s[100005];
struct node1 {
  int a[805];
} s1[10005];
bool cmp(node a, node b) {
  if (a.n != b.n)
    return a.n < b.n;
  else
    return a.m > b.m;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i].c);
    scanf("%d", &s[i].n);
    scanf("%d", &s[i].m);
  }
  std::sort(s, s + n, cmp);
  for (int i = 0; i < n; i++) {
    s1[s[i].n].a[s[i].m]++;
  }
  int mm = 1, t = 0, k = 0, j;
  for (int i = 0; i < n; i++) {
    if (mm == s[i].n) {
      if (s1[mm].a[s[i].m] == 2) {
        printf("%s %s\n", s[i].c, s[i + 1].c);
        mm++;
      } else if (s1[mm].a[s[i].m] == 1 && s1[mm].a[s[i + 1].m] == 1) {
        printf("%s %s\n", s[i].c, s[i + 1].c);
        mm++;
      } else {
        printf("?\n");
        mm++;
      }
    }
  }
  return 0;
}
