#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  using T = tuple<long long, long long, long long, long long>;
  vector<long long> x(n), y(n), z(n);
  for (long long i = (0); i < ((n)); ++i) cin >> x[i] >> y[i] >> z[i];
  vector<long long> flag(n, 0);
  vector<pair<long long, long long> > ans;
  for (long long i = (0); i < ((n)); ++i) {
    if (flag[i]) continue;
    flag[i]++;
    bool check = true;
    long long X = (1LL << 60), Y, Z, id;
    for (long long j = (0); j < ((n)); ++j) {
      if (flag[j]) continue;
      if (X == (1LL << 60)) {
        X = x[j], Y = y[j], Z = z[j];
        id = j;
        continue;
      }
      if (((min(x[i], X)) <= (x[j]) && (x[j]) < (max(x[i], X) + 1)) &&
          ((min(y[i], Y)) <= (y[j]) && (y[j]) < (max(y[i], Y) + 1)) &&
          ((min(z[i], Z)) <= (z[j]) && (z[j]) < (max(z[i], Z) + 1))) {
        X = x[j], Y = y[j], Z = z[j];
        id = j;
        continue;
      }
    }
    flag[id]++;
    ans.push_back(pair<long long, long long>(i + 1, id + 1));
  }
  for (long long i = (0); i < ((n / 2)); ++i)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
