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