#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, string> > > vec;
char s[1000006];
int main() {
  int n, m;
  int x, y;
  cin >> n >> m;
  vec.resize(m);
  for (int i = 0; i < n; i++) {
    scanf("%s %d %d", s, &x, &y);
    string s1;
    for (int j = 0; j < strlen(s); j++) {
      s1.push_back(s[j]);
    }
    vec[x - 1].push_back(make_pair(y, s1));
  }
  for (int i = 0; i < m; i++) {
    sort(vec[i].rbegin(), vec[i].rend());
    if (vec[i].size() > 2 && vec[i][1].first == vec[i][2].first) {
      printf("?\n");
    } else {
      cout << vec[i][0].second << " " << vec[i][1].second << endl;
    }
  }
  return 0;
}
