#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6;
const long long MOD = 1610612741;
const long long mod = 1e9 + 7;
const long long INF = 1e15 + 5040;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
vector<pair<int, string>> reg[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    int x, sc;
    cin >> s >> x >> sc;
    x--;
    reg[x].push_back(make_pair(sc, s));
  }
  for (int i = 0; i < m; i++)
    sort(reg[i].begin(), reg[i].end()), reverse(reg[i].begin(), reg[i].end());
  for (int i = 0; i < m; i++) {
    if (reg[i].size() == 2) {
      cout << reg[i][0].second << ' ' << reg[i][1].second << '\n';
      continue;
    }
    if (reg[i][2].first != reg[i][1].first) {
      cout << reg[i][0].second << ' ' << reg[i][1].second << '\n';
      continue;
    }
    cout << "?\n";
  }
}
