#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
int n, m, r, p;
vector<pair<int, string> > mp[MAX];
string s;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s >> r >> p, mp[r].push_back({-p, s});
  for (int i = 1; i <= m; i++) {
    sort(mp[i].begin(), mp[i].end());
    if (mp[i].size() > 2 && mp[i][1].first == mp[i][2].first)
      cout << "?\n";
    else
      cout << mp[i][0].second << " " << mp[i][1].second << '\n';
  }
}
