#include <bits/stdc++.h>
namespace io {
int F() {
  int F = 1, n = 0;
  char ch;
  while ((ch = getchar()) != '-' && (ch < '0' || ch > '9'))
    ;
  ch == '-' ? F = 0 : n = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0';
  return F ? n : -n;
}
long long G() {
  long long F = 1, n = 0;
  char ch;
  while ((ch = getchar()) != '-' && (ch < '0' || ch > '9'))
    ;
  ch == '-' ? F = 0 : n = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0';
  return F ? n : -n;
}
}  // namespace io
int R(int l, int r) { return (rand() << 15 | rand()) % (r - l + 1) + l; }
int x[2222], y[2222], z[2222];
int ab(int x) { return x > 0 ? x : -x; }
int vis[2222];
int main() {
  int n = io::F();
  for (int i = 1; i <= n; ++i) x[i] = io::F(), y[i] = io::F(), z[i] = io::F();
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      int min = 0x3f3f3f3f, mp;
      for (int j = 1; j <= n; ++j)
        if (j != i && !vis[j])
          if ((min > (ab(x[i] - x[j]) + ab(y[i] - y[j]) + ab(z[i] - z[j]))
               ? min = (ab(x[i] - x[j]) + ab(y[i] - y[j]) + ab(z[i] - z[j])),
               1 : 0))
            mp = j;
      printf("%d %d\n", i, mp);
      vis[i] = vis[mp] = 1;
    }
  return 0;
}
