#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 123;
const long long INF = (long long)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;
string s;
int reg, k;
vector<pair<int, string> > v[N];
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> reg >> k;
    v[reg].push_back(make_pair(k, s));
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end());
    reverse(v[i].begin(), v[i].end());
    if ((int)(v[i].size()) >= 3 && v[i][1].first == v[i][2].first)
      cout << '?' << endl;
    else
      cout << v[i][0].second << ' ' << v[i][1].second << endl;
  }
}
