#include <bits/stdc++.h>
using namespace std;
int x[2501], y[2501], z[2501], n, i, j, little, nom;
bool pole[2501];
int Abs(int a) { return (a < 0 ? -a : a); }
int rast(int abcd, int ABCD, int z1, int x2, int y2, int z2) {
  return Abs(abcd - x2) + Abs(ABCD - y2) + Abs(z1 - z2);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i];
  for (i = 1; i <= n - 1; i++)
    if (!pole[i]) {
      little = 1000000000;
      for (j = i + 1; j <= n; j++)
        if ((!pole[j]) && (rast(x[i], y[i], z[i], x[j], y[j], z[j]) < little)) {
          little = rast(x[i], y[i], z[i], x[j], y[j], z[j]);
          nom = j;
        }
      pole[i] = pole[nom] = true;
      cout << i << " " << nom << '\n';
    }
  return 0;
}
