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