#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<vector<pair<long long int, string>>> teams(m);
  for (int i = 0; i < n; i++) {
    string s;
    long long int team, val;
    cin >> s >> team >> val;
    teams[team - 1].push_back({val, s});
  }
  for (int i = 0; i < m; i++) {
    sort(teams[i].rbegin(), teams[i].rend());
  }
  vector<string> ans(m, "?");
  for (int i = 0; i < m; i++) {
    if (teams[i].size() < 2) continue;
    if (teams[i].size() == 2) {
      ans[i] = teams[i][0].second;
      ans[i] += " " + teams[i][1].second;
    } else {
      if (teams[i][1].first != teams[i][2].first) {
        ans[i] = teams[i][0].second;
        ans[i] += " " + teams[i][1].second;
      }
    }
  }
  for (auto i : ans) cout << i << endl;
}
int main() { solve(); }
