#include <bits/stdc++.h>
using namespace std;
const int MAXM = 10010;
int n, m;
vector<pair<int, string> > val[MAXM];
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a, b;
    string s;
    cin >> s >> a >> b;
    val[a - 1].push_back(make_pair(b, s));
  }
  for (int i = 0; i < m; i++) {
    sort(val[i].begin(), val[i].end());
    reverse(val[i].begin(), val[i].end());
    if (val[i].size() > 2 && val[i][1].first == val[i][2].first)
      cout << "?\n";
    else
      cout << val[i][0].second << " " << val[i][1].second << "\n";
  }
  return 0;
}
