#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384626433832795;
const long long INF = 1e9 + 7;
const double EPS = 1 / 1e9;
const long long MOD = 1000000007;
const int N = 1010;
void solve() {
  int n;
  vector<pair<pair<int, int>, string> > a;
  string s;
  int x, y;
  int m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> x >> y;
    a.push_back(make_pair(make_pair(x, y), s));
  }
  sort(a.begin(), a.end());
  int t = 1, pos = -1;
  for (int i = 0; i < n; i++) {
    if (a[i].first.first == t) {
      pos = i;
    } else if (pos != -1) {
      if (pos > 1 && a[pos - 2].first.first != a[pos - 1].first.first)
        cout << a[pos].second << " " << a[pos - 1].second << endl;
      else if (pos > 1 && a[pos - 2].first.first == a[pos - 1].first.first &&
               a[pos - 2].first.second != a[pos - 1].first.second)
        cout << a[pos].second << " " << a[pos - 1].second << endl;
      else if (pos == 1)
        cout << a[pos].second << " " << a[pos - 1].second << endl;
      else
        cout << "?" << endl;
      t++;
      pos = -1;
    }
  }
  if (pos != -1) {
    if (pos > 1 && a[pos - 2].first.first != a[pos - 1].first.first)
      cout << a[pos].second << " " << a[pos - 1].second << endl;
    else if (pos > 1 && a[pos - 2].first.first == a[pos - 1].first.first &&
             a[pos - 2].first.second != a[pos - 1].first.second)
      cout << a[pos].second << " " << a[pos - 1].second << endl;
    else if (pos == 1)
      cout << a[pos].second << " " << a[pos - 1].second << endl;
    else
      cout << "?" << endl;
    t++;
    pos = -1;
  }
}
int main() {
  int k1 = 1;
  while (k1--) solve();
  return 0;
}
