#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> X(n), Y(n), Z(n);
  for (int i = 0; i < n; ++i) {
    cin >> X[i] >> Y[i] >> Z[i];
  }
  priority_queue<tuple<long long, int, int>> Q;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      Q.emplace(
          -((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]) +
            (Z[i] - Z[j]) * (Z[i] - Z[j])),
          i, j);
    }
  }
  vector<bool> used(n, false);
  while (Q.size()) {
    long long d;
    int i, j;
    tie(d, i, j) = Q.top();
    Q.pop();
    if (used[i] or used[j]) continue;
    cout << i + 1 << " " << j + 1 << endl;
    used[i] = true;
    used[j] = true;
  }
}
