#include <bits/stdc++.h>
using namespace std;
struct dat {
  int score, no;
};
char name[100005][15];
priority_queue<pair<int, int>> score[10005];
int main() {
  int n, m, a, b;
  int t1, t1er, t2, t2er;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s %d %d", name[i], &a, &b);
    score[a].push({b, i});
  }
  for (int i = 1; i <= m; i++) {
    t1 = score[i].top().first;
    t1er = score[i].top().second;
    score[i].pop();
    t2 = score[i].top().first;
    t2er = score[i].top().second;
    score[i].pop();
    if (!score[i].empty() && t2 == score[i].top().first) {
      printf("?\n");
      continue;
    }
    printf("%s %s\n", name[t1er], name[t2er]);
  }
}
