#include <bits/stdc++.h>
using namespace std;
const int M = 10005;
struct node {
  char name[15];
  int sco;
  bool operator<(node a) const { return sco > a.sco; }
} tmp;
int n, m;
vector<node> reg[M];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int team;
    scanf("%s%d%d", tmp.name, &team, &tmp.sco);
    reg[team].push_back(tmp);
  }
  for (int i = 1; i <= m; ++i) sort(reg[i].begin(), reg[i].end());
  for (int i = 1; i <= m; ++i) {
    if (reg[i].size() > 2) {
      if (reg[i][1].sco == reg[i][2].sco)
        puts("?");
      else
        printf("%s %s\n", reg[i][0].name, reg[i][1].name);
    } else
      printf("%s %s\n", reg[i][0].name, reg[i][1].name);
  }
}
