#include <bits/stdc++.h>
using namespace std;
class point {
 public:
  long long x, y, z, id;
};
void zfn(vector<point> &p) {
  map<long long, point> byz;
  long long n = p.size();
  for (long long i = (0); i < (n); i++) {
    byz[p[i].z] = p[i];
  }
  long long c = 0;
  point last;
  for (auto &i : byz) {
    if (c == 0)
      last = i.second;
    else
      cout << last.id << ' ' << i.second.id << '\n';
    c = c ^ 1;
  }
  p.clear();
  if (c == 1) p.push_back(last);
}
void yfn(vector<point> &p) {
  map<long long, vector<point>> byy;
  for (auto &i : p) {
    byy[i.y].push_back(i);
  }
  long long c1 = 0;
  point last;
  for (auto &i : byy) {
    zfn(i.second);
    ;
    if (!i.second.empty()) {
      if (c1 == 0) {
        last = i.second[0];
      } else {
        cout << last.id << ' ' << i.second[0].id << '\n';
      }
      c1 ^= 1;
      ;
    }
  }
  p.clear();
  if (c1 == 1) p.push_back(last);
}
void solve() {
  long long n;
  cin >> n;
  vector<point> p(n);
  for (long long i = (0); i < (n); i++) {
    cin >> p[i].x >> p[i].y >> p[i].z;
    p[i].id = i + 1;
  }
  map<long long, vector<point>> byx;
  for (long long i = (0); i < (n); i++) byx[p[i].x].push_back(p[i]);
  long long c = 0;
  point last;
  for (auto &pp : byx) {
    yfn(pp.second);
    if (!pp.second.empty()) {
      if (c == 0)
        last = pp.second[0];
      else
        cout << last.id << ' ' << pp.second[0].id << '\n';
      c = c ^ 1;
    }
  }
}
signed main() {
  cin.tie(NULL), ios_base::sync_with_stdio(false), cout.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
