#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int OO = 1000000000;
struct member {
  string name;
  int reg;
  int score;
};
bool comp(member a, member b) { return a.score > b.score; }
int main() {
  std::ios::sync_with_stdio(false);
  member ms[100007];
  int regs[10007];
  pair<int, int> scs[10007];
  string ans[10007];
  for (int i = 0; i <= 10001; i++) regs[i] = 2;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string a;
    int x, y;
    cin >> a >> x >> y;
    ms[i].name = a;
    ms[i].reg = x;
    ms[i].score = y;
  }
  sort(ms, ms + n, comp);
  for (int i = 0; i < n; i++) {
    if (regs[ms[i].reg] == 2) {
      ans[ms[i].reg] = ms[i].name;
      scs[ms[i].reg].first = ms[i].score;
      regs[ms[i].reg] = 1;
    } else if (regs[ms[i].reg] == 1) {
      ans[ms[i].reg] += " " + ms[i].name;
      scs[ms[i].reg].second = ms[i].score;
      regs[ms[i].reg] = 0;
    } else {
      if (ms[i].score == scs[ms[i].reg].first ||
          ms[i].score == scs[ms[i].reg].second)
        ans[ms[i].reg] = "?";
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << "\n";
  }
}
