#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
string name[N];
int group[N];
int pont[N];
vector<pair<int, int> > v[N];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> name[i] >> group[i] >> pont[i];
    v[group[i]].push_back(make_pair(pont[i], i));
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end());
    reverse(v[i].begin(), v[i].end());
  }
  for (int i = 1; i <= m; i++) {
    if (v[i].size() > 2 && v[i][1].first == v[i][2].first) {
      cout << "?\n";
    } else {
      cout << name[v[i][0].second] << ' ' << name[v[i][1].second] << endl;
    }
  }
  return 0;
}
