#include <bits/stdc++.h>
using namespace std;
struct res {
  int p;
  string s;
};
bool cmp(res a, res b) { return a.p > b.p; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, rr, pp;
  string ss;
  cin >> n >> m;
  vector<res> v[m + 1];
  res temp;
  for (int i = 0; i < n; i++) {
    cin >> ss >> rr >> pp;
    temp.s = ss;
    temp.p = pp;
    v[rr].push_back(temp);
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end(), cmp);
    if (v[i].size() > 2 && v[i][1].p == v[i][2].p)
      cout << "?\n";
    else
      cout << v[i][0].s << " " << v[i][1].s << endl;
  }
}
