#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
struct P {
  int first, second, z;
};
inline long long ds(const P& a, const P& b) {
  return (long long)(a.first - b.first) * (a.first - b.first) +
         (long long)(a.second - b.second) * (a.second - b.second) +
         (long long)(a.z - b.z) * (a.z - b.z);
}
int a, b, c, d, n, m, k;
pair<P, int> mas[50002];
bool used[50002];
int main() {
  srand(std::chrono::duration_cast<std::chrono::microseconds>(
            std::chrono::high_resolution_clock::now().time_since_epoch())
            .count() +
        time(0));
  scanf("%d", &n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    scanf("%d%d%d", &mas[i].first.first, &mas[i].first.second, &mas[i].first.z);
    mas[i].second = i;
  }
  random_shuffle(mas, mas + n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    if (used[i]) continue;
    long long bd = -1;
    auto p = mas[i].first;
    int v = -1;
    for (int _n(n - 1), j(i + 1); j <= _n; j++) {
      if (used[j]) continue;
      long long cd = ds(p, mas[j].first);
      if (bd == -1 || cd < bd) {
        bd = cd;
        v = j;
      }
    }
    used[v] = 1;
    printf("%d %d\n", mas[i].second + 1, mas[v].second + 1);
  }
}
