#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<pair<int, int>, pair<int, int> > > v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first.first >> v[i].first.second >> v[i].second.first;
    v[i].second.second = i + 1;
  }
  while (!v.empty()) {
    sort(v.begin(), v.end());
    int x = v.back().first.first;
    int y = v.back().first.second;
    int z = v.back().second.first;
    int pos = v.back().second.second;
    v.pop_back();
    int ind = 0;
    long long d = 1e10;
    for (int i = 0; i < (int)v.size(); i++) {
      long long dist = abs(v[i].first.first - x);
      dist += abs(v[i].first.second - y);
      dist += abs(v[i].second.first - z);
      if (dist < d) {
        d = dist;
        ind = i;
      }
    }
    cout << pos << " " << v[ind].second.second << endl;
    v.erase(v.begin() + ind);
  }
}
