#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int T = 1;
  for (int tc = 1; tc <= T; tc++) {
    int n;
    cin >> n;
    vector<vector<int>> points(n, vector<int>(3));
    for (int i = 0; i < n; i++) {
      int x, y, z;
      cin >> x >> y >> z;
      points[i] = {x, y, z};
    }
    vector<bool> rm(n, false);
    int i = 0;
    while (i < n - 1) {
      int j = i + 1;
      while (j < n && rm[j]) j++;
      int k = j + 1;
      while (k < n) {
        if (!rm[k] &&
            (points[k][0] >= min(points[i][0], points[j][0]) &&
             points[k][0] <= max(points[i][0], points[j][0])) &&
            (points[k][1] >= min(points[i][1], points[j][1]) &&
             points[k][1] <= max(points[i][1], points[j][1])) &&
            (points[k][2] >= min(points[i][2], points[j][2]) &&
             points[k][2] <= max(points[i][2], points[j][2]))) {
          j = k;
        }
        k++;
      }
      cout << i + 1 << " " << j + 1 << "\n";
      rm[i] = true;
      rm[j] = true;
      while (i < n && rm[i]) i++;
    }
  }
  return 0;
}
