#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
std::vector<pair<int, string> > v[10000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    int a, b;
    cin >> s >> a >> b;
    pair<int, string> ans;
    ans.first = b;
    ans.second = s;
    v[a].push_back(ans);
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 1; i <= m; i++) {
    int size = v[i].size();
    if (v[i].size() == 2) {
      cout << v[i][1].second << ' ' << v[i][0].second << '\n';
    } else if (v[i][size - 2].first != v[i][size - 3].first) {
      cout << v[i][size - 1].second << ' ' << v[i][size - 2].second << '\n';
    } else
      cout << '?' << '\n';
  }
  return 0;
}
