#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<pair<int, string>> reg[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string sur;
    int where, pt;
    cin >> sur >> where >> pt;
    where--;
    reg[where].push_back({-pt, sur});
  }
  for (int i = 0; i < m; i++) {
    sort(reg[i].begin(), reg[i].end());
    if (reg[i].size() < 3 || reg[i][1].first - reg[i][2].first)
      cout << reg[i][0].second << ' ' << reg[i][1].second << "\n";
    else
      cout << "?\n";
  }
}
