#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
struct pt {
  int x;
  int y;
  int z;
  int idx;
};
bool ptcmp(const pt& a, const pt& b) {
  if (a.x < b.x) return true;
  if (b.x < a.x) return false;
  if (a.y < b.y) return true;
  if (b.y < a.y) return false;
  if (a.z < b.z) return true;
  if (b.z < a.z) return false;
}
int main() {
  int i, n;
  cin >> n;
  list<pt> li;
  vector<pt> v(n);
  vector<bool> used(n);
  vector<pt> vf(n);
  for (i = 0; i < n; i++) {
    cin >> v[i].x >> v[i].y >> v[i].z;
    v[i].idx = i + 1;
    used[i] = false;
    li.push_back(v[i]);
  }
  li.sort(ptcmp);
  vector<int> res;
  pt v1, v2;
  while (!li.empty()) {
    v1 = li.front();
    res.push_back(v1.idx);
    li.pop_front();
    if (li.front().x == v1.x) {
      v2 = li.front();
      if (v2.y == v1.y) {
        res.push_back(v2.idx);
        li.pop_front();
      } else {
        auto a = li.begin();
        auto b = li.begin();
        while (b != li.end()) {
          if ((*b).x != v1.x) break;
          if ((*b).y != v2.y) break;
          if ((*b).z > v1.z) break;
          a = b;
          b++;
        }
        res.push_back((*a).idx);
        li.erase(a);
      }
    } else {
      v2 = li.front();
      auto a = li.begin();
      auto b = li.begin();
      auto c = li.begin();
      while (b != li.end()) {
        if ((*b).x != v2.x) break;
        if ((*b).y > v1.y) break;
        if ((*b).y > (*a).y) {
          a = b;
          c = b;
        } else {
          if ((*b).z <= v1.z) {
            c = b;
          }
        }
        b++;
      }
      res.push_back((*c).idx);
      li.erase(c);
    }
  }
  for (i = 0; i < n; i += 2) {
    cout << res[i] << " " << res[i + 1] << endl;
  }
}
