#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10;
struct P {
  int x, y, z;
  vector<pair<long long, int> > pp;
} p[maxn];
bool vis[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].z);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      long long tmp = 1ll * (p[i].x - p[j].x) * (p[i].x - p[j].x) +
                      1ll * (p[i].y - p[j].y) * (p[i].y - p[j].y) +
                      1ll * (p[i].z - p[j].z) * (p[i].z - p[j].z);
      p[i].pp.push_back({tmp, j});
    }
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    sort(p[i].pp.begin(), p[i].pp.end());
    for (auto x : p[i].pp) {
      if (vis[x.second]) continue;
      printf("%d %d\n", i, x.second);
      vis[i] = vis[x.second] = true;
      break;
    }
  }
  return 0;
}
