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