#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const long long LINF = 3e18;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, string> > > a(m + 1);
  for (int i = 0; i < n; i++) {
    string name;
    int reg, pts;
    cin >> name >> reg >> pts;
    a[reg].push_back(make_pair(pts, name));
  }
  for (int i = 1; i <= m; i++) {
    sort((a[i]).begin(), (a[i]).end());
    int sz = a[i].size();
    if (sz != 2 && a[i][sz - 2].first == a[i][sz - 3].first) {
      cout << '?';
    } else {
      cout << a[i][sz - 1].second << " " << a[i][sz - 2].second;
    }
    cout << '\n';
  }
  return 0;
}
