#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LINF = numeric_limits<int>::max();
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const int MAXN = 10005;
vector<pair<int, string>> a[MAXN];
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
void solve() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  for (int i = 0; i < n; ++i) {
    string s;
    int reg, score;
    cin >> s >> reg >> score;
    --reg;
    a[reg].push_back(make_pair(score, s));
  }
  for (int i = 0; i < m; ++i) {
    sort(a[i].rbegin(), a[i].rend());
  }
  for (int i = 0; i < m; ++i) {
    if (a[i].size() == 2) {
      cout << a[i][0].second << ' ' << a[i][1].second << "\n";
    } else {
      if (a[i][1].first == a[i][2].first) {
        cout << "?\n";
      } else {
        cout << a[i][0].second << ' ' << a[i][1].second << "\n";
      }
    }
  }
}
int main() {
  if (!1) {
    freopen(
        "GoBig"
        ".in",
        "r", stdin);
    freopen(
        "GoBig"
        ".out",
        "w", stdout);
  }
  int t = 1;
  while (t--) {
    solve();
  }
}
