#include <bits/stdc++.h>
using namespace std;
int n, m, t, p;
string s;
vector<pair<int, string> > vc[500005];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> t >> p;
    vc[t].push_back(make_pair(p, s));
  }
  for (int i = 1; i <= m; i++) {
    sort(vc[i].begin(), vc[i].end());
    reverse(vc[i].begin(), vc[i].end());
    if (vc[i][1].first == vc[i][2].first && vc[i].size() >= 3)
      cout << "?\n";
    else {
      cout << vc[i][0].second << " " << vc[i][1].second << endl;
    }
  }
}
