#include <bits/stdc++.h>
using namespace std;
struct cons {
  string s;
  int reg, points, pos;
};
bool my(cons &a, cons &b) {
  if (a.reg < b.reg)
    return 1;
  else if (a.reg == b.reg && a.points > b.points)
    return 1;
  else if (a.reg == b.reg && a.points == b.points && a.pos < b.pos)
    return 1;
  else
    return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  cons A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i].s >> A[i].reg >> A[i].points;
    A[i].pos = i;
  }
  sort(A, A + n, my);
  vector<int> V;
  for (int i = 0; i < n; i++) {
    V.clear();
    V.push_back(A[i].points);
    int tr = A[i].reg, j = i + 1;
    while (A[j].reg == tr) {
      V.push_back(A[j].points);
      j++;
    }
    if (V.size() < 2)
      cout << "?" << endl;
    else if (V.size() > 2 && V[1] == V[2])
      cout << "?" << endl;
    else {
      cout << A[i].s << " " << A[i + 1].s << endl;
    }
    i = j - 1;
  }
}
