#include <bits/stdc++.h>
using namespace std;
struct node {
  string name;
  int region;
  int score;
} a[100100];
vector<node> save[100100];
bool cmp(node x, node y) { return x.score > y.score; }
int main() {
  int n, m;
  cin >> n >> m;
  string na;
  int re, sc;
  for (int i = 0; i < n; i++) {
    cin >> na >> re >> sc;
    a[i].name = na;
    a[i].region = re;
    a[i].score = sc;
    save[re].push_back(a[i]);
  }
  for (int i = 1; i <= m; i++) {
    sort(save[i].begin(), save[i].end(), cmp);
    if (save[i].size() > 2 && save[i][1].score == save[i][2].score)
      cout << "?" << endl;
    else
      cout << save[i][0].name << " " << save[i][1].name << endl;
  }
  return 0;
}
