#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
vector<pair<int, string> > r[N];
int main() {
  int p, n, m, i, a;
  string s;
  cin >> n >> m;
  for (i = 0; i < n; ++i) {
    cin >> s >> a >> p;
    r[a].push_back(make_pair(p, s));
  }
  for (i = 1; i <= m; ++i)
    sort(r[i].begin(), r[i].end(), greater<pair<int, string> >());
  for (i = 1; i <= m; ++i) {
    if (r[i].size() > 2) {
      if (r[i][0].first == r[i][2].first || r[i][1].first == r[i][2].first)
        printf("?\n");
      else
        cout << r[i][0].second << " " << r[i][1].second << endl;
    } else {
      cout << r[i][0].second << " " << r[i][1].second << endl;
    }
  }
}
