#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<pair<int, int>, pair<int, int> > > ar;
  for (int i = 1; i <= n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    ar.push_back({{x, y}, {z, i}});
  }
  while (!ar.empty()) {
    sort(ar.begin(), ar.end());
    int x = ar.back().first.first;
    int y = ar.back().first.second;
    int z = ar.back().second.first;
    int id = ar.back().second.second;
    ar.pop_back();
    int mx = 1e10;
    int pos = 0;
    for (int i = 0; i < (int)ar.size(); i++) {
      long long dif = abs(ar[i].first.first - x);
      dif += abs(ar[i].first.second - y);
      dif += abs(ar[i].second.first - z);
      if (dif < mx) {
        mx = dif;
        pos = i;
      }
    }
    cout << id << " " << ar[pos].second.second << "\n";
    ar.erase(ar.begin() + pos);
  }
  return 0;
}
