#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int m, n;
  cin >> n >> m;
  int ans[100005][2];
  tuple<int, int, string> a[100005];
  for (int i = 0; i < n; i++) {
    ans[i][0] = ans[i][1] = -1;
    int x, y;
    string z;
    cin >> z >> x >> y;
    a[i] = make_tuple(y, x, z);
  }
  sort(a, a + n);
  bool fail[100005] = {};
  for (int i = n - 1; i >= 0; i--) {
    int curm = get<1>(a[i]);
    if (ans[curm][0] == -1)
      ans[curm][0] = i;
    else if (ans[curm][1] == -1)
      ans[curm][1] = i;
    else if (get<0>(a[ans[curm][1]]) == get<0>(a[i]))
      fail[curm] = true;
  }
  for (int i = 1; i <= m; i++) {
    if (fail[i])
      cout << "?\n";
    else
      cout << get<2>(a[ans[i][0]]) << ' ' << get<2>(a[ans[i][1]]) << '\n';
  }
  return 0;
}
