#include <bits/stdc++.h>
using namespace std;
void my_assert(bool q) {
  if (!q)
    while (true)
      ;
}
int n, m, k, b;
vector<pair<int, string> > a[200000];
string s;
int main() {
  iostream::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> k >> b;
    k--;
    a[k].push_back(make_pair(b, s));
  }
  for (int i = 0; i < m; i++) {
    sort(a[i].begin(), a[i].end());
    reverse(a[i].begin(), a[i].end());
    if (a[i].size() <= 2 || a[i][1].first != a[i][2].first) {
      cout << a[i][0].second << " " << a[i][1].second << "\n";
    } else
      cout << "?\n";
  }
  return 0;
}
