#include <bits/stdc++.h>
using namespace std;
class p {
 public:
  int x, y, z;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  p a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].z;
  }
  vector<int> vis(n + 1);
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      int id = -1;
      p pr;
      pr.x = -1;
      pr.y = -1;
      pr.z = -1;
      for (int j = 1; j <= n; j++) {
        if (i == j) continue;
        if (vis[j] == 0 && pr.x == -1) {
          pr.x = a[j].x;
          pr.y = a[j].y;
          pr.z = a[j].z;
          id = j;
        } else if (vis[j] == 0 && min(a[i].x, pr.x) <= a[j].x &&
                   a[j].x <= max(a[i].x, pr.x) && min(a[i].y, pr.y) <= a[j].y &&
                   a[j].y <= max(a[i].y, pr.y) && min(a[i].z, pr.z) <= a[j].z &&
                   a[j].z <= max(a[i].z, pr.z)) {
          pr.x = a[j].x;
          pr.y = a[j].y;
          pr.z = a[j].z;
          id = j;
        }
      }
      cout << i << " " << id << endl;
      vis[i] = 1;
      vis[id] = 1;
    }
  }
}
