#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
template <typename T>
void update(T &x, T y, T mod) {
  x = x + y > mod ? x + y - mod : x + y;
}
const int INF = (1ll << 30);
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 5e4 + 7;
struct Point {
  int x, y, z, id;
} p[N];
vector<Point> v1, v2, v3, res1, res2;
int n;
inline bool cmp(Point a, Point b) { return a.x < b.x; }
inline bool cmp1(Point a, Point b) { return a.y < b.y; }
inline bool cmp2(Point a, Point b) { return a.z < b.z; }
inline void solve1D() {
  sort(v1.begin(), v1.end(), cmp);
  if (v1.size() >= 2)
    for (int i = 0; i < v1.size() - 1; i += 2)
      printf("%d %d\n", v1[i].id, v1[i + 1].id);
  if (v1.size() & 1) res1.push_back(v1[v1.size() - 1]);
  v1.clear();
}
inline void solve2D() {
  sort(v2.begin(), v2.end(), cmp1);
  for (int i = 0, j; i < v2.size(); i = j) {
    j = i;
    while (j < v2.size() && v2[j].y == v2[i].y) v1.push_back(v2[j]), j++;
    solve1D();
    v1.clear();
  }
  if (res1.size() >= 2)
    for (int i = 0; i < res1.size() - 1; i += 2)
      printf("%d %d\n", res1[i].id, res1[i + 1].id);
  if (res1.size() & 1) res2.push_back(res1[res1.size() - 1]);
  res1.clear();
}
inline void solve3D() {
  sort(v3.begin(), v3.end(), cmp2);
  for (int i = 0, j; i < v3.size(); i = j) {
    j = i;
    while (j < v3.size() && v3[j].z == v3[i].z) v2.push_back(v3[j]), j++;
    solve2D();
    v2.clear();
  }
  if (res2.size() >= 2)
    for (int i = 0; i < res2.size() - 1; i += 2)
      printf("%d %d\n", res2[i].id, res2[i + 1].id);
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(p[i].x);
    read(p[i].y);
    read(p[i].z);
    p[i].id = i;
    v3.push_back(p[i]);
  }
  solve3D();
  return 0;
}
