#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, z, i, j, k, a, b;
  std::ios::sync_with_stdio(false);
  cin >> n >> z;
  string s;
  k = n;
  map<string, int> m;
  vector<string> v[z + 1];
  while (k--) {
    cin >> s >> a >> b;
    m[s] = b;
    v[a].push_back(s);
  }
  for (i = 1; i <= z; i++) {
    vector<int> p;
    for (j = 0; j < v[i].size(); j++) p.push_back(m[v[i][j]]);
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    int flag = 1;
    if (p.size() > 2) {
      map<int, int> M;
      for (j = 0; j < p.size(); j++) {
        M[p[j]]++;
      }
      int x = 2;
      for (j = 0; j < p.size() && x != 0; j++) {
        if (M[p[j]] == 1)
          x--;
        else if (x == 2 && M[p[j]] == 2)
          x -= 2;
        else {
          x--;
          flag = 0;
        }
      }
    }
    if (flag) {
      pair<int, string> y[v[i].size()];
      for (j = 0; j < v[i].size(); j++) {
        y[j].second = v[i][j];
        y[j].first = m[v[i][j]];
      }
      sort(y, y + v[i].size());
      reverse(y, y + v[i].size());
      cout << y[0].second << " " << y[1].second << "\n";
    } else
      cout << "?\n";
  }
}
