#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &);
template <size_t n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
                                                  const tuple<T...> &) {}
template <size_t n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
                                                 const tuple<T...> &t) {
  os << (n == 0 ? "" : " ") << get<n>(t);
  _ot<n + 1>(os, t);
}
template <class... T>
ostream &operator<<(ostream &os, const tuple<T...> &t) {
  _ot<0>(os, t);
  return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (size_t i = 0; i < v.size(); i++)
    os << v[i] << (i + 1 == v.size() ? "" : ", ");
  return os;
}
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
void fastios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
auto const inf = numeric_limits<int>::max() / 8;
int main() {
  fastios();
  int n, m;
  while (cin >> n >> m) {
    map<int, string> getName;
    vector<vector<pair<int, int>>> scores(m);
    for (int i = 0; i < (int)(n); i++) {
      string name;
      int r;
      int s;
      cin >> name >> r >> s;
      --r;
      scores[r].emplace_back(s, i);
      getName[i] = name;
    }
    for (int i = 0; i < (int)(m); i++) {
      sort(begin(scores[i]), end(scores[i]));
      reverse(begin(scores[i]), end(scores[i]));
    }
    for (int i = 0; i < (int)(m); i++) {
      if (scores[i].size() == 2) {
        cout << getName[scores[i][0].second] << ' ';
        cout << getName[scores[i][1].second] << '\n';
      } else if (scores[i][1].first != scores[i][2].first) {
        cout << getName[scores[i][0].second] << ' ';
        cout << getName[scores[i][1].second] << '\n';
      } else {
        cout << "?" << '\n';
      }
    }
  }
}
