#include <bits/stdc++.h>
using namespace std;
map<int, vector<pair<int, pair<int, int>>>> xs;
int solve_y(vector<pair<int, int>> values) {
  sort(values.begin(), values.end());
  for (int i = 0; i + 1 < (int)values.size(); i += 2) {
    printf("%d %d\n", values[i].second, values[i + 1].second);
  }
  if ((int)values.size() % 2 == 1)
    return values.back().second;
  else
    return 0;
}
int solve_x(vector<pair<int, pair<int, int>>> values) {
  map<int, vector<pair<int, int>>> ys;
  for (auto &x : values) {
    ys[x.second.first].push_back({x.second.second, x.first});
  }
  vector<int> rem;
  for (auto &pr : ys) {
    int p = solve_y(pr.second);
    if (p) rem.push_back(p);
  }
  for (int i = 0; i + 1 < (int)rem.size(); i += 2) {
    printf("%d %d\n", rem[i], rem[i + 1]);
  }
  if ((int)rem.size() % 2 == 1)
    return rem.back();
  else
    return 0;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    xs[x].push_back({i + 1, {y, z}});
  }
  vector<int> rem;
  for (auto &pr : xs) {
    int p = solve_x(pr.second);
    if (p) rem.push_back(p);
  }
  assert((int)rem.size() % 2 == 0);
  for (int i = 0; i < (int)rem.size(); i += 2) {
    printf("%d %d\n", rem[i], rem[i + 1]);
  }
  return 0;
}
