#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000 + 50;
const int INF = 0x3f3f3f3f;
int vis[100010];
struct Node {
  string name;
  int num;
  int score;
};
bool cmp(Node a, Node b) { return a.score > b.score; }
map<int, int> mapv[MAX_N];
vector<Node> v[MAX_N];
int main() {
  memset(vis, 0, sizeof(vis));
  string name;
  int n, m;
  cin >> n >> m;
  int num, score;
  for (int i = 1; i <= m; i++) v[i].clear();
  for (int i = 0; i < n; i++) {
    Node node;
    cin >> name >> num >> score;
    node.name = name;
    node.num = num;
    node.score = score;
    v[num].push_back(node);
  }
  for (int i = 1; i <= m; i++) {
    sort(v[i].begin(), v[i].end(), cmp);
    if (v[i].size() > 2 && v[i][1].score == v[i][2].score)
      puts("?");
    else
      cout << v[i][0].name << " " << v[i][1].name << endl;
  }
  return 0;
}
