#include <bits/stdc++.h>
using namespace std;
int n, m, id[100010], key[100010], m1[10010], c1[10010], m2[10010], c2[10010],
    ty[10010], ans[10010][2];
char na[100010][12];
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", &na[i]);
    scanf("%d%d", &id[i], &key[i]);
    if (key[i] > m1[id[i]]) {
      m2[id[i]] = m1[id[i]], c2[id[i]] = c1[id[i]];
      m1[id[i]] = key[i], c1[id[i]] = 1;
    } else if (key[i] == m1[id[i]])
      c1[id[i]]++;
    else if (key[i] > m2[id[i]])
      m2[id[i]] = key[i], c2[id[i]] = 1;
    else if (key[i] == m2[id[i]])
      c2[id[i]]++;
  }
  for (int i = 1; i <= m; i++)
    if (c1[i] > 2)
      ty[i] = 3;
    else if (c1[i] == 2)
      ty[i] = 1;
    else if (c2[i] > 1)
      ty[i] = 3;
    else
      ty[i] = 2;
  for (int i = 1; i <= n; i++)
    if (ty[id[i]] == 1 && key[i] == m1[id[i]]) {
      if (ans[id[i]][0])
        ans[id[i]][1] = i;
      else
        ans[id[i]][0] = i;
    } else if (ty[id[i]] == 2 && key[i] >= m2[id[i]]) {
      if (ans[id[i]][0])
        ans[id[i]][1] = i;
      else
        ans[id[i]][0] = i;
    }
  for (int i = 1; i <= m; i++)
    if (ty[i] != 3)
      printf("%s %s\n", na[ans[i][0]], na[ans[i][1]]);
    else
      puts("?");
  return 0;
}
