#include <bits/stdc++.h>
using namespace std;
vector<map<int, vector<string> > > ab(1000002);
map<int, vector<string> >::reverse_iterator it;
int main() {
  int n, m, t, sc, res = 0;
  cin >> n >> m;
  string s;
  for (int i = 1; i <= n; i++) {
    cin >> s >> t >> sc;
    ab[t][sc].push_back(s);
  }
  for (int i = 1; i <= m; i++) {
    int foo = 1, cnt = 0;
    string x, y;
    for (it = (ab[i]).rbegin(); it != (ab[i]).rend(); it++) {
      if (it == ab[i].rbegin() && int((ab[i][it->first]).size()) == 2) {
        x = ab[i][it->first][0];
        y = ab[i][it->first][1];
        break;
      }
      if (int((ab[i][it->first]).size()) > 1) {
        foo = 0;
        break;
      }
      cnt++;
      if (cnt == 1) {
        x = ab[i][it->first][0];
      } else {
        y = ab[i][it->first][0];
        break;
      }
    }
    if (!foo) {
      cout << "?";
    } else {
      cout << x << " " << y;
    }
    cout << "\n";
  }
  return 0;
}
