#include <bits/stdc++.h>
using namespace std;
static bool cmp(pair<string, int> x, pair<string, int> y) {
  return x.second > y.second;
}
void Contest(int m, vector<vector<pair<string, int>>> &a) {
  for (int i = 1; i <= m; i++) {
    int n = a[i].size();
    sort(a[i].begin(), a[i].end(), cmp);
    if (n == 2 || a[i][1].second > a[i][2].second)
      cout << a[i][0].first << " " << a[i][1].first << endl;
    else
      cout << "?\n";
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<string, int>>> a(m + 1);
  for (int i = 0; i < n; i++) {
    string name;
    int point, region;
    cin >> name >> region >> point;
    a[region].push_back(make_pair(name, point));
  }
  Contest(m, a);
  return 0;
}
