#include <bits/stdc++.h>
using namespace std;
char s[100001][15];
vector<pair<int, int> > v[10001];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i]);
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    v[a].push_back(make_pair(b, i));
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end());
    reverse(v[i].begin(), v[i].end());
    if (v[i].size() < 3) {
      printf("%s %s\n", s[v[i][0].second], s[v[i][1].second]);
    } else {
      if (v[i][1].first == v[i][2].first) {
        printf("?\n");
      } else
        printf("%s %s\n", s[v[i][0].second], s[v[i][1].second]);
    }
  }
}
