#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-4;
const long double PI = acos((long double)-1.0);
const long long int MOD = 1e9 + 7;
long long int powmod(long long int a, long long int b, long long int mod) {
  long long int res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int debug = 1;
template <typename T, typename S>
void DBG(pair<T, S> p) {
  if (debug) cout << p.first << " " << p.second << endl;
}
template <typename T>
void DBG(vector<T> v) {
  if (debug) {
    for (T t : v) cout << t << "  ";
    cout << endl;
  }
}
template <typename T>
void DBG(T t) {
  if (debug) cout << t << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, string>>> v(n);
  for (int i = 0; i < (n); ++i) {
    string name;
    int region;
    int points;
    cin >> name >> region >> points;
    v[region - 1].push_back({points, name});
  }
  for (int i = 0; i < (m); ++i) {
    sort(v[i].begin(), v[i].end(),
         [](pair<int, string> const &a, pair<int, string> const &b) {
           if (a.first < b.first) return true;
           if (a.first == b.first) return a.second < b.second;
           return false;
         });
    int s = v[i].size();
    if (s >= 3 && v[i][s - 2].first == v[i][s - 3].first) {
      cout << "?" << endl;
    } else {
      cout << v[i][s - 2].second << " " << v[i][s - 1].second << endl;
    }
  }
}
