#include <bits/stdc++.h>
using namespace std;
struct as {
  int a, b, num;
};
int fun(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first > b.first;
  }
  return a.second > b.second;
}
bool check(string a) {
  int c, b;
  c = b = 0;
  for (auto d : a) {
    if (d == '4') {
      c++;
    } else {
      b++;
    }
  }
  return (b == c);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> nombres;
  vector<pair<int, int> > soda[m];
  for (int i = 0; i < n; i++) {
    string a;
    int grup, lv;
    cin >> a >> grup >> lv;
    nombres.push_back(a);
    soda[grup - 1].push_back(pair<int, int>(lv, i));
  }
  for (int i = 0; i < m; i++) {
    sort(soda[i].begin(), soda[i].end());
    int tam = soda[i].size() - 1;
    if (tam >= 2) {
      if (soda[i][tam - 1].first > soda[i][tam - 2].first) {
        cout << nombres[soda[i][tam].second] << " "
             << nombres[soda[i][tam - 1].second];
      } else {
        cout << "?";
      }
    } else {
      cout << nombres[soda[i][tam].second] << " "
           << nombres[soda[i][tam - 1].second];
    }
    cout << endl;
  }
}
