#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool ckmn(T &a, T b) {
  T c = a;
  a = min(a, b);
  return a != c;
}
template <typename T>
bool ckmx(T &a, T b) {
  T c = a;
  a = max(a, b);
  return a != c;
}
map<int, map<int, vector<pair<int, int>>>> pts;
int main() {
  int n;
  scanf("%i", &n);
  for (int i = 1; i <= n; i++) {
    int x, y, z;
    scanf("%i %i %i", &x, &y, &z);
    pts[x][y].push_back({z, i});
  }
  vector<pair<int, int>> ans;
  vector<int> X;
  for (auto it : pts) {
    vector<int> Y;
    for (auto jt : it.second) {
      vector<pair<int, int>> p = jt.second;
      sort(p.begin(), p.end());
      for (int i = 0; i + 1 < p.size(); i += 2) {
        ans.push_back({p[i].second, p[i + 1].second});
      }
      if (p.size() & 1) Y.push_back(p.back().second);
    }
    for (int i = 0; i + 1 < Y.size(); i += 2) {
      ans.push_back({Y[i], Y[i + 1]});
    }
    if (Y.size() & 1) X.push_back(Y.back());
  }
  for (int i = 0; i + 1 < X.size(); i += 2) {
    ans.push_back({X[i], X[i + 1]});
  }
  for (auto e : ans) printf("%i %i\n", e.first, e.second);
  return 0;
}
