#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 5e4 + 6;
struct point {
  int x, y, z;
  int id;
} p[N], m[N];
bool cmp(point a, point b) {
  if (a.x != b.x) return a.x < b.x;
  if (a.y != b.y) return a.y < b.y;
  return a.z < b.z;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n;
  m = n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].x >> p[i].y >> p[i].z;
    p[i].id = i;
  }
  sort(p + 1, p + 1 + n, cmp);
  for (int i = 1; i <= n - 1; i++) {
    if (p[i].x == p[i + 1].x && p[i].y == p[i + 1].y) {
      cout << p[i].id << " " << p[i + 1].id << endl;
      p[i].x = p[i + 1].x = 1e9;
      m -= 2;
      i++;
    }
  }
  sort(p + 1, p + 1 + n, cmp);
  n = m;
  for (int i = 1; i <= n - 1; i++) {
    if (p[i].x == p[i + 1].x) {
      cout << p[i].id << " " << p[i + 1].id << endl;
      p[i].x = p[i + 1].x = 1e9;
      m -= 2;
      i++;
    }
  }
  sort(p + 1, p + 1 + n, cmp);
  n = m;
  for (int i = 1; i <= n - 1; i++) {
    cout << p[i].id << " " << p[i + 1].id << endl;
    i++;
  }
  return 0;
}
