#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<tuple<int, int, int, int>> v;
  for (int i = 0; i < (int)(n); i++) {
    int a, b, c;
    cin >> a >> b >> c;
    v.emplace_back(a, b, c, i);
  }
  sort(v.begin(), v.end());
  vector<int> ans;
  for (int i = 0; i < (int)(n / 2); i++) {
    int xa, ya, za, ia;
    tie(xa, ya, za, ia) = v[0];
    int xb, yb, zb, ib;
    tie(xb, yb, zb, ib) = v[1];
    int k = 1;
    for (int j = 2; j < v.size(); j++) {
      int xc, yc, zc, ic;
      tie(xc, yc, zc, ic) = v[j];
      if (min(xa, xb) <= xc && xc <= max(xa, xb) && min(ya, yb) <= yc &&
          yc <= max(ya, yb) && min(za, zb) <= zc && zc <= max(za, zb)) {
        tie(xb, yb, zb, ib) = tie(xc, yc, zc, ic);
        k = j;
      }
    }
    ans.push_back(ia + 1);
    ans.push_back(ib + 1);
    v.erase(v.begin() + k);
    v.erase(v.begin());
  }
  for (int i = 0; i < (int)(n / 2); i++) {
    cout << ans[i * 2] << ' ' << ans[i * 2 + 1] << endl;
  }
  return 0;
}
