#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
string to_str(T str) {
  stringstream stream;
  stream << str;
  return stream.str();
}
template <typename T>
int to_int(T num) {
  int val;
  stringstream stream;
  stream << num;
  stream >> val;
  return val;
}
vector<string> split(const string& s, char delim) {
  vector<string> elems;
  stringstream ss(s);
  string item;
  while (getline(ss, item, delim)) elems.push_back(item);
  return elems;
}
const int dr[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int T2 = 105;
const int T3 = 1005;
const int T4 = 10005;
const int T5 = 100005;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, string> > vec[100000];
  for (int i = 0; i < (n); i++) {
    string s;
    int x, y;
    cin >> s >> x >> y;
    vec[x].push_back(make_pair(y, s));
  }
  for (int i = 1; i <= m; i++) {
    sort(vec[i].begin(), vec[i].end());
    reverse(vec[i].begin(), vec[i].end());
    if (vec[i].size() > 2 && vec[i][1].first == vec[i][2].first)
      puts("?");
    else
      cout << vec[i][0].second << " " << vec[i][1].second << endl;
  }
  return 0;
}
