#include <bits/stdc++.h>
using namespace std;
map<int, map<int, map<int, int> > > mapp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    mapp[x][y][z] = i + 1;
  }
  int lastZ = -1, lastY = -1, lastX = -1;
  for (auto x : mapp) {
    lastY = -1;
    for (auto y : x.second) {
      lastZ = -1;
      for (auto z : y.second) {
        if (lastZ != -1) {
          cout << lastZ << " " << z.second << "\n";
          lastZ = -1;
        } else {
          lastZ = z.second;
        }
      }
      if (lastZ != -1) {
        if (lastY == -1) {
          swap(lastZ, lastY);
        } else {
          cout << lastZ << " " << lastY << "\n";
          lastZ = -1;
          lastY = -1;
        }
      }
    }
    if (lastY != -1) {
      if (lastX == -1) {
        swap(lastX, lastY);
      } else {
        cout << lastX << " " << lastY << "\n";
        lastX = -1;
        lastY = -1;
      }
    }
  }
}
