#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void io() {}
long long fast_exp(long long base, int exp, int m) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) {
      res = (res * base) % m;
    }
    base = (base * base) % m;
    exp /= 2;
  }
  return res % m;
}
vector<pair<long long, string> > v[10001];
long long dp[2001][4];
int main() {
  io();
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  while (n--) {
    string s;
    long long r, p;
    cin >> s >> r >> p;
    v[r].push_back(make_pair(p, s));
  }
  for (int i = 1; i <= int(m); ++i) {
    sort(v[i].begin(), v[i].end());
    int siz = v[i].size();
    if (siz == 2) {
      cout << v[i][siz - 1].second << " " << v[i][siz - 2].second << '\n';
    } else if ((v[i][siz - 2].first == v[i][siz - 3].first)) {
      cout << "?" << '\n';
    } else {
      cout << v[i][siz - 1].second << " " << v[i][siz - 2].second << '\n';
    }
  }
}
