#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
vector<pair<int, string> > p[10001];
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) {
    string s;
    int x, y;
    cin >> s;
    cin >> x >> y;
    p[x].push_back(pair<int, string>(y, s));
  }
  for (int i = (1); i <= (m); ++i) sort((p[i]).begin(), (p[i]).end());
  for (int i = (1); i <= (m); ++i) reverse((p[i]).begin(), (p[i]).end());
  for (int i = (1); i <= (m); ++i) {
    if (((int)(p[i]).size()) == 2 || p[i][1].first != p[i][2].first) {
      cout << p[i][0].second << " " << p[i][1].second << "\n";
    } else
      cout << "?\n";
  }
}
