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