#include <bits/stdc++.h>
using namespace std;
template <typename T>
T nextInt() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') {
    p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * p;
}
const int maxN = (int)3e5 + 10;
const int INF = (int)1e9 + 5;
const int mod = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 5;
int n, m;
vector<pair<int, string> > a[maxN];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  while (n--) {
    string z;
    int x, y;
    cin >> z >> x >> y;
    ::a[x].push_back(make_pair(y, z));
  }
  for (int i = 1; i <= m; ++i) {
    sort(a[i].begin(), a[i].end());
    reverse(a[i].begin(), a[i].end());
    vector<string> b;
    int l = 0;
    while (l < a[i].size() && a[i][l].first == a[i][0].first && b.size() <= 2) {
      b.push_back(a[i][l].second);
      l++;
    }
    while (l < a[i].size() && a[i][l].first == a[i][1].first && b.size() <= 2) {
      b.push_back(a[i][l].second);
      l++;
    }
    if (b.size() == 2) {
      cout << b[0] << ' ' << b[1] << '\n';
    } else {
      cout << '?' << '\n';
    }
  }
  return 0;
}
