#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const int mod = 1000000007;
struct node {
  char s[20];
  int id, v;
} a[100005];
bool cmp(node a, node b) {
  if (a.id == b.id) return a.v > b.v;
  return a.id < b.id;
}
int vis[100005];
int main() {
  int n, m, i, j;
  while (~scanf("%d%d", &n, &m)) {
    for (i = 0; i < n; ++i) scanf("%s%d%d", a[i].s, &a[i].id, &a[i].v);
    sort(a, a + n, cmp);
    memset(vis, 0, sizeof(vis));
    a[n].v = -1;
    a[n + 1].v = -2;
    for (i = 0; i < n; ++i) {
      if (!vis[a[i].id]) {
        if ((a[i].id == a[i + 1].id) &&
            ((a[i + 2].id != a[i + 1].id) ||
             (a[i + 1].id == a[i + 2].id && (a[i + 2].v != a[i + 1].v)))) {
          printf("%s %s\n", a[i].s, a[i + 1].s);
        } else
          printf("?\n");
        vis[a[i].id] = 1;
      }
    }
  }
}
