#include <bits/stdc++.h>
using namespace std;
using ll = int;
vector<pair<ll, string>> con[101010];
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int reg, sc;
  string name;
  while (n--) {
    cin >> name;
    cin >> reg;
    cin >> sc;
    con[reg].push_back(make_pair(sc, name));
  }
  for (int i = 1; i <= m; i++) {
    sort(con[i].begin(), con[i].end());
    reverse(con[i].begin(), con[i].end());
    if ((int)con[i].size() > 2 && con[i][1].first == con[i][2].first) {
      cout << "?\n";
    } else {
      cout << con[i][0].second << " " << con[i][1].second << endl;
    }
  }
  return 0;
}
