#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int M = 10005;
const int md = 1000000007;
int n, m, i, a, b, last;
string s, x, y;
set<pair<int, string> > st[M];
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (i = 1; i <= n; ++i) {
    cin >> s >> a >> b;
    st[a].insert(make_pair(b, s));
  }
  for (i = 1; i <= m; ++i) {
    set<pair<int, string> >::iterator it = st[i].end();
    --it;
    x = it->second;
    --it;
    y = it->second;
    if (it == st[i].begin()) {
      cout << x << " " << y << "\n";
      continue;
    }
    last = it->first;
    --it;
    if ((it->first) == last)
      cout << "?\n";
    else
      cout << x << " " << y << "\n";
  }
}
