#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
struct man {
  string s;
  int poi;
};
vector<man> t[maxn];
bool cmp(man a, man b) {
  if (a.poi != b.poi)
    return a.poi > b.poi;
  else
    return a.s < b.s;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  string s;
  int x, y;
  for (int i = 0; i <= m; ++i) t[i].clear();
  for (int i = 0; i < n; ++i) {
    cin >> s;
    scanf("%d%d", &x, &y);
    man mm;
    mm.poi = y;
    mm.s = s;
    t[x].push_back(mm);
  }
  for (int i = 1; i <= m; ++i) {
    sort(t[i].begin(), t[i].end(), cmp);
    if (t[i].size() < 2 || (t[i].size() >= 3 && t[i][1].poi == t[i][2].poi))
      printf("?\n");
    else {
      cout << t[i][0].s << " " << t[i][1].s << endl;
    }
  }
}
