#include <bits/stdc++.h>
using namespace std;
const long long inf = 2147483647;
const int maxn = 100001;
const int maxm = 500001;
int n;
struct pos {
  int x, y, z;
  int f;
} ps[maxn];
bool operator<(pos a, pos b) {
  if (a.x < b.x) return 1;
  if (a.x > b.x) return 0;
  if (a.y < b.y) return 1;
  if (a.y > b.y) return 0;
  if (a.z < b.z) return 1;
  return 0;
}
int mk[maxn];
int fdnx(int i) {
  for (int j = i + 1; j <= n; ++j) {
    if (ps[j].x != ps[i].x) return -1;
    if (mk[j] == 0) {
      return j;
    }
  }
  return -1;
}
int fd(int i) {
  int no = fdnx(i);
  if (no == -1) return -1;
  if (ps[no].y == ps[i].y) return no;
  int y = ps[no].y;
  while (ps[no].y == y) {
    int nw = fdnx(no);
    if (nw == -1) return no;
    if (ps[nw].y != y) return no;
    if (ps[nw].z > ps[i].z) return no;
    no = nw;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &ps[i].x, &ps[i].y, &ps[i].z);
    ps[i].f = i;
  }
  sort(&ps[1], &ps[n + 1]);
  for (int i = 1; i <= n; ++i) {
    if (mk[i] == 0) {
      int d = fd(i);
      if (d == -1) continue;
      printf("%d %d\n", ps[i].f, ps[d].f);
      mk[i] = mk[d] = 1;
    }
  }
  int fl = 0;
  for (int i = 1; i <= n; ++i) {
    if (mk[i] == 0) {
      if (fl == 0) {
        printf("%d ", ps[i].f);
      } else {
        printf("%d\n", ps[i].f);
      }
      fl = 1 - fl;
    }
  }
  return 0;
}
