#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int N = 15e4 + 10;
struct a {
  string name;
  int score;
};
vector<a> vecs[10010];
int n, m;
bool cmp(const a &ta, const a &tb) { return ta.score > tb.score; }
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; ++i) {
    char s[12];
    int t, score;
    scanf("%s%d%d", s, &t, &score);
    a ta;
    ta.name = s;
    ta.score = score;
    vecs[t].push_back(ta);
  }
  for (i = 1; i <= m; ++i) {
    sort(vecs[i].begin(), vecs[i].end(), cmp);
    if (vecs[i][0].score == vecs[i][1].score) {
      if (vecs[i].size() > 2) {
        if (vecs[i][2].score == vecs[i][1].score)
          printf("?\n");
        else
          printf("%s %s\n", vecs[i][0].name.c_str(), vecs[i][1].name.c_str());
      } else {
        printf("%s %s\n", vecs[i][0].name.c_str(), vecs[i][1].name.c_str());
      }
    } else {
      if (vecs[i].size() > 2) {
        if (vecs[i][2].score == vecs[i][1].score)
          printf("?\n");
        else
          printf("%s %s\n", vecs[i][0].name.c_str(), vecs[i][1].name.c_str());
      } else {
        printf("%s %s\n", vecs[i][0].name.c_str(), vecs[i][1].name.c_str());
      }
    }
  }
  return 0;
}
