#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int n, m;
vector<pair<int, string> > reg[N];
char str[11];
bool hav[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int x, y, i = 0; i < n; ++i) {
    scanf("%s", str);
    scanf("%d%d", &x, &y);
    x--;
    reg[x].push_back({-y, str});
  }
  for (int i = 0; i < m; ++i) {
    sort(reg[i].begin(), reg[i].end());
    if (reg[i].size() > 2 && (reg[i][2].first == reg[i][0].first ||
                              reg[i][1].first == reg[i][2].first))
      puts("?");
    else
      printf("%s %s\n", reg[i][0].second.c_str(), reg[i][1].second.c_str());
  }
  return 0;
}
