#include <bits/stdc++.h>
using namespace std;
const int SZ = 52;
const double EPS = 1e-9;
const int MOD = 100000008;
const int INF = (1 << 30) - 1;
const double PI = 2 * acos(0.0);
template <class T>
T MIN(T a, T b) {
  return (a < b) ? a : b;
}
template <class T>
T MAX(T a, T b) {
  return (a > b) ? a : b;
}
template <class T>
void SWAP(T &a, T &b) {
  T c;
  c = a;
  a = b;
  b = c;
}
template <class T>
T GCD(T a, T b) {
  T c;
  while (b > 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
bool CMP(int a, int b) { return (a > b); }
bool sort_by_value(const pair<string, int> &a, const pair<string, int> &b) {
  return (a.second > b.second);
}
int main() {
  string s;
  int i, n, m, p, x;
  pair<string, int> d, e, f;
  cin >> n >> x;
  vector<pair<string, int> > qc[x];
  for (int i = 0; i < x; i++) {
    qc[i].clear();
  }
  while (n--) {
    cin >> s >> m >> p;
    qc[m - 1].push_back(make_pair(s, p));
  }
  for (i = 0; i < x; i++) {
    sort(qc[i].begin(), qc[i].end(), sort_by_value);
    d = qc[i][0];
    e = qc[i][1];
    if (qc[i].size() > 2) {
      f = qc[i][2];
      if (e.second == f.second) {
        cout << "?" << endl;
      } else {
        cout << d.first << " " << e.first << endl;
      }
    } else {
      cout << d.first << " " << e.first << endl;
    }
  }
  return 0;
}
