#include <bits/stdc++.h>
using namespace std;
vector<pair<int, string>> v[100010];
int main() {
  int n, m;
  cin >> m >> n;
  string cit;
  int regiune, rez;
  while (m--) {
    cin >> cit;
    cin >> regiune >> rez;
    v[regiune].push_back({-rez, cit});
  }
  for (int i = 1; i <= n; i++) {
    sort(v[i].begin(), v[i].end());
    if (v[i].size() > 2 && v[i][1].first == v[i][2].first)
      cout << "?\n";
    else
      cout << v[i][0].second << ' ' << v[i][1].second << '\n';
  }
}
