#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, string>> a;
  for (int i = 0; i < n; i++) {
    pair<pair<int, int>, string> b;
    pair<int, int> c;
    cin >> b.second;
    cin >> c.first;
    cin >> c.second;
    b.first = c;
    a.push_back(b);
  }
  pair<pair<int, int>, string> b;
  pair<int, int> c;
  c.first = m + 1;
  c.second = 0;
  b.first = c;
  b.second = "wow";
  a.push_back(b);
  sort(a.begin(), a.end());
  int last = 0;
  string aaa[m];
  string bbb[m];
  for (int i = 1; i <= m; i++) {
    int p = -1;
    int q = -1;
    int r = -1;
    while (((a.at(last)).first).first == i) {
      p = q;
      q = r;
      r = ((a.at(last)).first).second;
      last += 1;
    }
    if (p == q) {
      aaa[i - 1] = "?";
      bbb[i - 1] = "";
    } else {
      aaa[i - 1] = (a.at(last - 1)).second;
      bbb[i - 1] = (a.at(last - 2)).second;
    }
  }
  for (int i = 0; i < m; i++) {
    if (aaa[i] == "?") {
      cout << "?\n";
    } else {
      cout << aaa[i] << " " << bbb[i] << "\n";
    }
  }
}
