#include <bits/stdc++.h>
using namespace std;
int n, i, j, x, y, z, o, u[179000], r[179000];
map<int, map<int, map<int, int>>> s;
int main() {
  for (cin >> n; i < n; i++) {
    cin >> x >> y >> z;
    s[z][y][x] = i + 1;
  }
  for (auto a : s)
    for (auto b : a.second) {
      i = 0;
      for (auto c : b.second) {
        o = c.second;
        r[j++] = o, u[o] = 1;
        i++;
      }
      if (i % 2) j--, u[r[j]] = 0;
    }
  for (auto a : s) {
    i = 0;
    for (auto b : a.second) {
      o = 0;
      for (auto c : b.second)
        if (!u[c.second]) {
          o = c.second;
          break;
        }
      if (!o) continue;
      r[j++] = o, u[o] = 1;
      i++;
    }
    if (i % 2) j--, u[r[j]] = 0;
  }
  i = 0;
  for (auto a : s)
    for (auto b : a.second)
      for (auto c : b.second)
        if (!u[c.second]) r[j++] = c.second, i ^= 1;
  for (i = 0; i < j; i++) cout << r[i] << (i & 1 ? "\n" : " ");
}
