#include <bits/stdc++.h>
using namespace std;
vector<pair<string, int> > v[100007];
bool comp(pair<string, int> x, pair<string, int> y) {
  return x.second > y.second;
}
int main() {
  int n, t, i, j, m, x, val, st, l;
  cin >> n >> m;
  string arr[n + 5];
  for (i = 0; i < n; i++) {
    cin >> arr[i] >> x >> val;
    v[x].push_back(make_pair(arr[i], val));
  }
  for (i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end(), comp);
    l = v[i].size();
    st = 0;
    if (l >= 3) {
      if (v[i][2].second == v[i][1].second) {
        cout << "?" << endl;
        st = 1;
      }
    }
    if (st == 0) cout << v[i][0].first << " " << v[i][1].first << endl;
  }
  return 0;
}
