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