#include <bits/stdc++.h>
using namespace std;
struct M {
  int x, y, z;
};
int dis(int x, int y) { return abs(x - y); }
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  M note[5000];
  vector<bool> vs(5000, 0);
  for (int i = 1; i <= n; i++) {
    cin >> note[i].x >> note[i].y >> note[i].z;
  }
  for (int i = 1; i <= n; i++) {
    int X = INT_MAX, Y = INT_MAX, Z = INT_MAX, now;
    if (!vs[i]) {
      for (int j = 1; j <= n; j++) {
        if (i != j && !vs[j]) {
          int disX = dis(note[i].x, note[j].x);
          int disY = dis(note[i].y, note[j].y);
          int disZ = dis(note[i].z, note[j].z);
          if (disX < X) {
            now = j;
          } else if (disX == X) {
            if (disY < Y)
              now = j;
            else if (disY == Y) {
              if (disZ < Z) now = j;
            }
          }
          if (now == j) {
            X = disX;
            Y = disY;
            Z = disZ;
          }
        }
      }
      cout << i << " " << now << endl;
      vs[i] = 1;
      vs[now] = 1;
    }
  }
}
