#include <bits/stdc++.h>
using namespace std;
struct Point {
  long long x, y, z;
  int num;
};
bool operator<(Point p1, Point p2) {
  if (p1.x != p2.x)
    return p1.x < p2.x;
  else if (p1.y != p2.y)
    return p1.y < p2.y;
  return p1.z < p2.z;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<Point> ps(n);
  for (int i = 0; i < n; ++i) {
    cin >> ps[i].x >> ps[i].y >> ps[i].z;
    ps[i].num = i;
  }
  sort(ps.begin(), ps.end());
  vector<Point> ps2;
  for (int i = 0; i < n;) {
    if (i + 1 == n || ps[i + 1].x != ps[i].x) {
      ps2.push_back(ps[i]);
      ++i;
    } else {
      int ni = i + 1;
      while (ni < n && ps[ni].x == ps[i].x) ++ni;
      vector<Point> ps3;
      for (int j = i; j < ni;)
        if (j + 1 == ni || ps[j + 1].y != ps[j].y) {
          ps3.push_back(ps[j]);
          ++j;
        } else {
          cout << ps[j].num + 1 << ' ' << ps[j + 1].num + 1 << "\n";
          j += 2;
        }
      for (int j = 0; j + 1 < (int)ps3.size(); j += 2)
        cout << ps3[j].num + 1 << ' ' << ps3[j + 1].num + 1 << "\n";
      if (ps3.size() % 2 != 0) ps2.push_back(ps3.back());
      i = ni;
    }
  }
  for (int i = 0; i < (int)ps2.size(); i += 2)
    cout << ps2[i].num + 1 << ' ' << ps2[i + 1].num + 1 << "\n";
  return 0;
}
