#include <bits/stdc++.h>
using namespace std;
const int N = 100086;
struct re {
  int pos, sc;
  string name;
} res[N];
bool cmp(re a, re b) {
  if (a.pos == b.pos) return a.sc > b.sc;
  return a.pos < b.pos;
}
int n, m;
string s;
int cs, score;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    cin >> res[i].name >> res[i].pos >> res[i].sc;
  }
  sort(res, res + n, cmp);
  if (res[1].pos == res[2].pos) {
    if (res[1].sc == res[2].sc)
      printf("?\n");
    else
      cout << res[0].name << " " << res[1].name << "\n";
  } else {
    cout << res[0].name << " " << res[1].name << "\n";
  }
  res[n].pos = res[n - 1].pos;
  res[n].sc = -1;
  for (int i = 2; i < n - 1; i++) {
    if (res[i].pos == res[i - 1].pos) continue;
    if (res[i + 1].pos == res[i + 2].pos) {
      if (res[i + 1].sc == res[i + 2].sc)
        printf("?\n");
      else
        cout << res[i].name << " " << res[i + 1].name << "\n";
    } else
      cout << res[i].name << " " << res[i + 1].name << "\n";
  }
  return 0;
}
