#include <bits/stdc++.h>
using namespace std;
int n, m;
bool f[1000005];
struct mzls {
  int x, y, z, id;
  bool operator<(const mzls &x1) const {
    if (x != x1.x) return x < x1.x;
    if (y != x1.y) return y > x1.y;
    return z > x1.z;
  }
} a[1000005];
int main() {
  int T = 1;
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
      scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z), a[i].id = i;
    for (int i = 1; i <= n; i++)
      if (!f[i]) {
        int i1;
        long long ml = 100000000000000ll;
        for (int j = i + 1; j <= n; j++)
          if (!f[j] && 1ll * abs(a[j].x - a[i].x) + abs(a[j].y - a[i].y) +
                               abs(a[j].z - a[i].z) <
                           ml)
            ml = 1ll * abs(a[j].x - a[i].x) + abs(a[j].y - a[i].y) +
                 abs(a[j].z - a[i].z),
            i1 = j;
        f[i] = f[i1] = 1;
        printf("%d %d\n", i, i1);
      }
  }
}
