#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *l = buf, *r = buf;
  return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r)
             ? EOF
             : *l++;
}
template <class T>
void read(T &x) {
  x = 0;
  int f = 1, ch = nc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 - '0' + ch;
    ch = nc();
  }
  x *= f;
}
template <class T>
inline bool Cmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <class T>
inline T ABS(T x) {
  return x < 0 ? -x : x;
}
const int inf = 1e9;
const int maxn = 2000 + 50;
int n, x[maxn], y[maxn], z[maxn];
bool vis[maxn];
inline int dist(int a, int b) {
  return ABS(x[a] - x[b]) + ABS(y[a] - y[b]) + ABS(z[a] - z[b]);
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) read(x[i]), read(y[i]), read(z[i]);
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      int k, d = inf;
      for (int j = i + 1; j <= n; ++j)
        if (!vis[j]) {
          if (Cmin(d, dist(i, j))) k = j;
        }
      printf("%d %d\n", i, k);
      vis[i] = vis[k] = 1;
    }
  return 0;
}
