#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
vector<tuple<int, int, int, int> > V;
int f(int lvl, int i) {
  if (lvl == 0)
    return get<0>(V[i]);
  else if (lvl == 1)
    return get<1>(V[i]);
  else
    return get<2>(V[i]);
}
int func(int l, int r, int lvl) {
  if (l == r) return get<3>(V[l]);
  int now = l;
  vector<int> U;
  for (int i = l + 1; i <= r; i++)
    if (f(lvl, i) > f(lvl, now)) {
      int k = func(now, i - 1, lvl + 1);
      if (k != -1) U.push_back(k);
      now = i;
    }
  int k = func(now, r, lvl + 1);
  if (k != -1) U.push_back(k);
  while (U.size() >= 2) {
    cout << U.back() << " ";
    U.pop_back();
    cout << U.back() << "\n";
    U.pop_back();
  }
  return ((U.empty()) ? -1 : U[0]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    V.push_back(make_tuple(x, y, z, i + 1));
  }
  sort(V.begin(), V.end());
  func(0, n - 1, 0);
}
