#include <bits/stdc++.h>
using namespace std;
map<long long, long long> M;
vector<pair<long long, string> > V[200005];
long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w,
    x, y, z, pre;
long long A[200005], B[200005];
string S, T;
set<long long> SS;
set<long long>::iterator it;
bool cmp(pair<long long, string> A, pair<long long, string> B) {
  return A.first > B.first;
}
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> S >> a >> p;
    V[a].push_back(make_pair(p, S));
  }
  for (i = 1; i <= m; i++) {
    sort(V[i].begin(), V[i].end(), cmp);
    if (V[i].size() >= 3) {
      if (V[i][1].first == V[i][2].first)
        cout << '?' << endl;
      else
        cout << V[i][0].second << ' ' << V[i][1].second << endl;
    } else
      cout << V[i][0].second << ' ' << V[i][1].second << endl;
  }
  return 0;
}
