#include <bits/stdc++.h>
using namespace std;
char s[100000][11];
struct pp {
  int id, mark;
  pp() { mark = -1; }
} a[10001][4];
int compare(pp x, pp y) { return (x.mark > y.mark); }
int main() {
  int n, m, mk, rg;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s%d%d", s[i], &rg, &mk);
    a[rg][3].id = i;
    a[rg][3].mark = mk;
    sort(a[rg], a[rg] + 4, compare);
  }
  for (int i = 1; i <= m; i++)
    if (a[i][1].mark == a[i][2].mark)
      printf("?\n");
    else
      printf("%s %s\n", s[a[i][0].id], s[a[i][1].id]);
  return 0;
}
