#include <bits/stdc++.h>
using namespace std;
struct point {
  string s;
  int p;
  bool operator<(const point &a) const {
    return a.p < p || (a.p == p && a.s < s);
  }
};
set<point> a[10010];
;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (n--) {
    string s;
    int num, p;
    cin >> s >> num >> p;
    point tmp;
    tmp.s = s;
    tmp.p = p;
    a[num].insert(tmp);
  }
  for (int i = 1; i <= m; i++) {
    set<point>::iterator it1;
    set<point>::iterator it2;
    it1 = a[i].begin();
    it1++;
    it2 = a[i].begin();
    it2++;
    it2++;
    if (it2 != a[i].end() && it1->p == it2->p)
      printf("?\n");
    else {
      it2 = a[i].begin();
      cout << it2->s << " " << it1->s << endl;
    }
  }
  return 0;
}
