#include <bits/stdc++.h>
using namespace std;
template <typename T>
T Abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
T const& Max(T const& a, T const& b) {
  return a > b ? a : b;
}
template <typename T>
T const& Min(T const& a, T const& b) {
  return a < b ? a : b;
}
template <typename T>
inline T gcd(T a, T b) {
  return (b ? gcd(b, a % b) : a);
}
template <typename T>
T sqaa(T a) {
  return a * a;
}
int main() {
  int m, n, i, j, k, l;
  string second;
  vector<pair<int, string> > v[10005];
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    cin >> second;
    scanf("%d %d", &k, &l);
    v[k].push_back({l, second});
  }
  for (i = 1; i <= m; i++) {
    sort(v[i].rbegin(), v[i].rend());
  }
  for (i = 1; i <= m; i++) {
    int a, b, c = -1;
    a = v[i][0].first;
    b = v[i][1].first;
    if (v[i].size() > 2) c = v[i][2].first;
    if (b == c)
      cout << "?\n";
    else
      cout << v[i][0].second << " " << v[i][1].second << endl;
  }
  return 0;
}
