#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<pair<pair<long long, long long>, pair<long long, long long> > > kavo;
  for (long long i = 0; i < n; ++i) {
    long long x, y, z;
    cin >> x >> y >> z;
    kavo.push_back({{z, y}, {x, i}});
  }
  sort(kavo.begin(), kavo.end());
  long long zch = kavo[0].first.first, ych = kavo[0].first.second,
            ver = kavo[0].second.second;
  vector<bool> used(n, false);
  vector<pair<long long, long long> > ans;
  for (long long i = 1; i < n; ++i) {
    long long z = kavo[i].first.first, y = kavo[i].first.second,
              x = kavo[i].second.first, ver2 = kavo[i].second.second;
    if (z == zch && y == ych && !used[ver2] && !used[ver]) {
      used[ver] = used[ver2] = true;
      ans.push_back({ver + 1, ver2 + 1});
      z = -1e9;
    } else if (!used[ver2]) {
      zch = z;
      ych = y;
      ver = ver2;
    }
  }
  for (long long i = 0; i < n; ++i)
    if (!used[kavo[i].second.second]) {
      ver = kavo[i].second.second;
      zch = kavo[i].first.first;
      break;
    }
  for (long long i = 1; i < n; ++i) {
    long long z = kavo[i].first.first, y = kavo[i].first.second,
              x = kavo[i].second.first, ver2 = kavo[i].second.second;
    if (z == zch && !used[ver2] && !used[ver] && ver != ver2) {
      used[ver] = used[ver2] = true;
      ans.push_back({ver + 1, ver2 + 1});
      z = -1e9;
    } else if (!used[ver2]) {
      zch = z;
      ver = ver2;
    }
  }
  for (long long i = 0; i < n; ++i)
    if (!used[kavo[i].second.second]) {
      ver = kavo[i].second.second;
      break;
    }
  for (long long i = 1; i < n; ++i) {
    long long z = kavo[i].first.first, y = kavo[i].first.second,
              x = kavo[i].second.first, ver2 = kavo[i].second.second;
    if (!used[ver2] && !used[ver] && ver != ver2) {
      used[ver] = used[ver2] = true;
      ans.push_back({ver + 1, ver2 + 1});
    } else if (!used[ver2])
      ver = ver2;
  }
  for (long long i = 0; i < n / 2; ++i)
    cout << ans[i].first << ' ' << ans[i].second << endl;
}
