#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int N = 1e5 + 5;
vector<pair<int, string> > a[N];
bool cmp(pair<int, string> a, pair<int, string> b) { return a.first > b.first; }
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    string name;
    int rr, score;
    cin >> name >> rr >> score;
    a[rr].push_back({score, name});
  }
  for (int i = 1; i <= m; ++i) {
    sort((a[i]).begin(), (a[i]).end(), cmp);
  }
  for (int i = 1; i <= m; ++i) {
    if ((int)a[i].size() > 2) {
      if ((a[i][0].first == a[i][2].first) ||
          (a[i][1].first == a[i][2].first)) {
        cout << '?' << endl;
      } else {
        cout << a[i][0].second << ' ' << a[i][1].second << endl;
      }
    } else {
      cout << a[i][0].second << ' ' << a[i][1].second << endl;
    }
  }
  return 0;
}
