#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1 << 30;
const long long N = 200000;
bool is_vowel_up(char c) {
  return c == 'A' || c == 'E' || c == 'I' || c == 'U' || c == 'O' || c == 'Y';
}
bool is_vowel_low(char c) {
  return c == 'a' || c == 'e' || c == 'i' || c == 'u' || c == 'o' || c == 'y';
}
long long Strtoll(string str) {
  stringstream second(str);
  long long x = 0;
  second >> x;
  return x;
}
string llostr(long long x) {
  stringstream second;
  second << x;
  string str = second.str();
  return str;
}
template <typename T>
T add(T a, T b) {
  return a + b >= MOD ? a + b - MOD : a + b;
}
template <typename T>
T sub(T a, T b) {
  return a - b < 0 ? a - b + MOD : a - b;
}
template <typename T>
T mul(T a, T b) {
  return (a * 1LL * b) % MOD;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int substr_cnt(string s, string p) {
  int i, ans = 0, len = p.size();
  for (int i = 0; i < s.size() - len + 1; i++) {
    if (p == s.substr(i, len)) ans++;
  }
  return ans;
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int fx[] = {1, 1, 1, 0, -1, -1, -1, 0};
int fy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
void file() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  file();
  int n, m;
  cin >> n >> m;
  vector<pair<int, string>> vp[n];
  while (n--) {
    string s;
    cin >> s;
    int id, src;
    cin >> id >> src;
    vp[id].push_back(make_pair(src, s));
  }
  for (int i = 1; i <= m; i++) {
    sort(vp[i].begin(), vp[i].end(), greater<pair<int, string>>());
    if (vp[i].size() > 2 && vp[i][1].first == vp[i][2].first)
      cout << "?"
           << "\n";
    else
      cout << vp[i][0].second << " " << vp[i][1].second << "\n";
  }
  return 0;
}
