#include <bits/stdc++.h>
using namespace std;
const long long N = 1e4 + 0.000001;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  deque<pair<long long, string> > v[m];
  for (long long i = 0; i < n; i++) {
    string name;
    long long team, score;
    cin >> name >> team >> score;
    v[team - 1].push_back({score, name});
  }
  for (long long i = 0; i < m; i++) {
    sort(v[i].rbegin(), v[i].rend());
    if (v[i].size() == 2) {
      cout << v[i][0].second << " " << v[i][1].second << endl;
      continue;
    }
    if (v[i][1].first == v[i][2].first)
      cout << "?" << endl;
    else
      cout << v[i][0].second << " " << v[i][1].second << endl;
  }
}
