#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
vector<vector<pair<string, int> > > de(100001);
string s;
bool cmp(const pair<string, int>& i, const pair<string, int>& j) {
  return i.second > j.second;
}
int main() {
  cin >> n >> m;
  while (n-- && cin >> s >> x >> y) de[x].push_back(make_pair(s, y));
  for (int i = 1; i <= m; i++) sort(de[i].begin(), de[i].end(), cmp);
  for (int i = 1; i <= m; i++) {
    if (de[i].size() > 2 && de[i][1].second == de[i][2].second)
      cout << "?\n";
    else
      cout << de[i][0].first << " " << de[i][1].first << endl;
  }
}
