#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<pair<int, int>, pair<int, int> > > A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i].first.first >> A[i].first.second >> A[i].second.first;
    A[i].second.second = i + 1;
  }
  while (!A.empty()) {
    sort(A.begin(), A.end());
    int x = A.back().first.first;
    int y = A.back().first.second;
    int z = A.back().second.first;
    int r = A.back().second.second;
    A.pop_back();
    int l, dist, res = INT_MAX;
    for (int i = 0; i < A.size(); i++) {
      dist = abs(A[i].first.first - x);
      dist += abs(A[i].first.second - y);
      dist += abs(A[i].second.first - z);
      if (dist < res) {
        res = dist;
        l = i;
      }
    }
    cout << r << " " << A[l].second.second << "\n";
    A.erase(A.begin() + l);
  }
  return 0;
}
