#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
vector<pair<int, string> > g[N];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string s;
  int team;
  int val;
  for (int i = 1; i <= n; i++) {
    cin >> s >> team >> val;
    g[team].push_back(make_pair(val, s));
  }
  for (int i = 1; i <= m; i++) {
    sort(g[i].begin(), g[i].end());
    reverse(g[i].begin(), g[i].end());
    if ((int)g[i].size() > 2 && g[i][2].first == g[i][1].first) {
      cout << "?\n";
      continue;
    }
    if ((int)g[i].size() > 2 && g[i][2].first == g[i][0].first) {
      cout << "?\n";
    } else {
      cout << g[i][0].second << " " << g[i][1].second << "\n";
    }
  }
  return 0;
}
