#include <bits/stdc++.h>
using namespace std;
struct pct {
  int x, y, z, nr;
} v[2005], a, b;
int main() {
  int n, i, p1, p2, k;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> v[i].x >> v[i].y >> v[i].z;
    v[i].nr = i;
  }
  for (k = 1; k <= n / 2; k++) {
    for (i = 1; i <= n; i++) {
      if (v[i].nr != -1) {
        a = v[i];
        p1 = i;
        break;
      }
    }
    for (i = i + 1; i <= n; i++) {
      if (v[i].nr != -1) {
        b = v[i];
        p2 = i;
        break;
      }
    }
    for (i = i + 1; i <= n; i++) {
      if (v[i].nr != -1 and min(a.x, b.x) <= v[i].x and
          v[i].x <= max(a.x, b.x) and min(a.y, b.y) <= v[i].y and
          v[i].y <= max(a.y, b.y) and min(a.z, b.z) <= v[i].z and
          v[i].z <= max(a.z, b.z)) {
        b = v[i];
        p2 = i;
      }
    }
    v[p1].nr = -1;
    v[p2].nr = -1;
    cout << p1 << " " << p2 << "\n";
  }
  return 0;
}
