#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int> > v(n);
  map<pair<int, int>, vector<pair<int, int> > > A;
  for (int i = 0; i < n; ++i) {
    v[i].resize(3);
    for (int j = 0; j < 3; ++j) {
      scanf("%d", &v[i][j]);
    }
    A[{v[i][0], v[i][1]}].push_back({v[i][2], i});
  }
  map<int, vector<pair<int, int> > > B;
  for (auto &x : A) {
    auto &w = x.second;
    sort(w.begin(), w.end());
    for (int i = 0; i + 1 < w.size(); i += 2) {
      printf("%d %d\n", w[i].second + 1, w[i + 1].second + 1);
    }
    if (w.size() & 1) {
      int x = w.back().second;
      B[v[x][0]].push_back({v[x][1], x});
    }
  }
  vector<pair<int, int> > C;
  for (auto &x : B) {
    auto &w = x.second;
    sort(w.begin(), w.end());
    for (int i = 0; i + 1 < w.size(); i += 2) {
      printf("%d %d\n", w[i].second + 1, w[i + 1].second + 1);
    }
    if (w.size() & 1) {
      int x = w.back().second;
      C.push_back({v[x][0], x});
    }
  }
  sort(C.begin(), C.end());
  for (int i = 0; i + 1 < C.size(); i += 2)
    printf("%d %d\n", C[i].second + 1, C[i + 1].second + 1);
  return 0;
}
