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