#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, string> > > rg(m, vector<pair<int, string> >(1));
  for (int i = 0; i < n; i++) {
    string sn;
    int r, s;
    cin >> sn;
    scanf("%d %d", &r, &s);
    rg[r - 1].push_back(make_pair(s, sn));
  }
  for (int i = 0; i < m; i++) {
    rg[i][0] = make_pair(-10, "xD");
    sort(rg[i].begin(), rg[i].end());
    reverse(rg[i].begin(), rg[i].end());
    cout << (rg[i][1].first == rg[i][2].first
                 ? "?"
                 : string(rg[i][0].second + " " + rg[i][1].second))
         << endl;
  }
}
