#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
vector<pair<int, string> > ar[10005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a, b;
    string s;
    cin >> s >> a >> b;
    ar[a].push_back({-b, s});
  }
  for (int i = 1; i <= m; i++) {
    sort(ar[i].begin(), ar[i].end());
    if ((int)(ar[i].size()) == 2)
      cout << ar[i][0].second << " " << ar[i][1].second << "\n";
    else if (ar[i][1].first != ar[i][2].first)
      cout << ar[i][0].second << " " << ar[i][1].second << "\n";
    else
      cout << "?\n";
  }
  return 0;
}
