#include <bits/stdc++.h>
using namespace std;
struct Point {
  long long int x, y, z;
};
long long int dist(Point &a, Point &b) {
  return abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z);
}
int main() {
  int n;
  cin >> n;
  deque<Point> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].z;
  }
  vector<bool> done(n + 1, false);
  for (int i = 1; i <= n; i++) {
    if (done[i]) {
      continue;
    }
    done[i] = true;
    int index = -1;
    long long int min_dist = 1e18;
    for (int j = i + 1; j <= n; j++) {
      if (done[j]) {
        continue;
      }
      long long int This_distance = dist(a[i], a[j]);
      if (index == -1 || min_dist > This_distance) {
        index = j;
        min_dist = This_distance;
      }
    }
    assert(index != -1);
    done[index] = true;
    cout << i << " " << index << "\n";
  }
  return 0;
}
