#include <bits/stdc++.h>
using namespace std;
int n;
vector<tuple<int, int, int, int>> tp, tp2;
vector<pair<int, int>> ans;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  int xi, yi, zi;
  for (int i = (0); i < (n); ++i) {
    cin >> xi >> yi >> zi;
    tp.emplace_back(xi, yi, zi, i);
  }
  sort(tp.begin(), tp.end());
  for (int i = (0); i < (n); ++i) {
    if (i + 1 < n && get<0>(tp[i]) == get<0>(tp[i + 1]) &&
        get<1>(tp[i]) == get<1>(tp[i + 1])) {
      ans.emplace_back(get<3>(tp[i]), get<3>(tp[i + 1]));
      ++i;
    } else
      tp2.emplace_back(tp[i]);
  }
  swap(tp, tp2);
  tp2.clear();
  n = tp.size();
  for (int i = (0); i < (n); ++i) {
    if (i + 1 < n && get<0>(tp[i]) == get<0>(tp[i + 1])) {
      ans.emplace_back(get<3>(tp[i]), get<3>(tp[i + 1]));
      ++i;
    } else
      tp2.emplace_back(tp[i]);
  }
  swap(tp, tp2);
  tp2.clear();
  n = tp.size();
  for (int i = (0); i < (n); ++i) {
    if (i + 1 < n && get<1>(tp[i]) == get<1>(tp[i + 1])) {
      ans.emplace_back(get<3>(tp[i]), get<3>(tp[i + 1]));
      ++i;
    } else
      tp2.emplace_back(tp[i]);
  }
  swap(tp, tp2);
  n = tp.size();
  for (int i = (0); i < (n - 1); ++i) {
    ans.emplace_back(get<3>(tp[i]), get<3>(tp[i + 1]));
    ++i;
  }
  for (auto i : ans) cout << i.first + 1 << " " << i.second + 1 << "\n";
  return 0;
}
