#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret *= a;
    a *= a;
    if (ret >= MOD) ret %= MOD;
    if (a >= MOD) a %= MOD;
    b >>= 1;
  }
  return ret;
}
long long inv(long long x) { return power(x, MOD - 2); }
const int N = 1e4 + 5;
int n, m;
vector<pair<int, string> > v[N];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    int reg, scr;
    cin >> s >> reg >> scr;
    v[reg].push_back(make_pair(scr, s));
  }
  for (int i = 0; i < N; i++) sort(v[i].begin(), v[i].end());
  for (int i = 0; i < N; i++) {
    if ((int)v[i].size() < 2) continue;
    int mx1 = v[i][(int)v[i].size() - 1].first,
        mx2 = v[i][(int)v[i].size() - 2].first, cnt1 = 0, cnt2 = 0;
    string s1 = v[i][(int)v[i].size() - 1].second,
           s2 = v[i][(int)v[i].size() - 2].second;
    for (int j = 0; j < (int)v[i].size(); j++) {
      int val = v[i][j].first;
      if (mx1 == val)
        ++cnt1;
      else if (mx2 == val)
        ++cnt2;
    }
    if (cnt1 > 2 || cnt2 > 2 || (cnt1 == 2 and cnt2) || (cnt2 == 2 and cnt1)) {
      cout << "?\n";
      continue;
    }
    cout << s1 << " " << s2 << "\n";
  }
}
