#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y, z;
  int num;
} a[100005];
int n, c[100005];
bool cmp(point p, point q) {
  if (p.x != q.x)
    return p.x < q.x;
  else if (p.y != q.y)
    return p.y < q.y;
  else
    return p.z < q.z;
}
int dist(point p, point q) {
  return abs(p.x - q.x) + abs(p.y - q.y) + abs(p.z - q.z);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].z);
    a[i].num = i + 1;
  }
  sort(a, a + n, cmp);
  for (int i = 0; i < n - 1; i++) {
    if (a[i].x == a[i + 1].x && a[i].y == a[i + 1].y) {
      printf("%d %d\n", a[i].num, a[i + 1].num);
      c[i] = c[i + 1] = 1;
      i++;
    }
  }
  int en = 1;
  for (int i = 0; i < n - 1;) {
    while (c[i]) i++;
    en = i + 1;
    while (c[en] && en < n) en++;
    if (en >= n) break;
    if (a[i].x == a[en].x) {
      printf("%d %d\n", a[i].num, a[en].num);
      c[i] = c[en] = 1;
      i = en + 1;
    } else
      i = en;
  }
  for (int i = 0; i < n - 1;) {
    while (c[i]) i++;
    en = i + 1;
    while (c[en] && en < n) en++;
    if (en >= n) break;
    printf("%d %d\n", a[i].num, a[en].num);
    c[i] = c[en] = 1;
    i = en + 1;
  }
}
