#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
vector<pair<pair<int, int>, string> > vec;
bool comp(pair<pair<int, int>, string> a, pair<pair<int, int>, string> b) {
  if (a.first.first != b.first.first)
    return a.first.first < b.first.first;
  else if (a.first.second != b.first.second)
    return a.first.second > b.first.second;
  else
    return a.second < b.second;
}
vector<pair<int, string> > l[10001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int a, b;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> a >> b;
    vec.push_back(make_pair(make_pair(a, b), s));
  }
  sort(vec.begin(), vec.end(), comp);
  for (int i = 0; i < n; i++) {
    l[vec[i].first.first].push_back(
        make_pair(vec[i].first.second, vec[i].second));
  }
  for (int i = 1; i <= m; i++) {
    if (l[i].size() >= 3 && l[i][1].first == l[i][2].first) {
      cout << "?\n";
    } else {
      cout << l[i][0].second << " " << l[i][1].second << "\n";
    }
  }
  return 0;
}
