#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
struct pt {
  long long x, y, z;
  long long id;
};
bool operator<(pt a, pt b) {
  return make_pair(make_pair(a.x, a.y), a.z) <
         make_pair(make_pair(b.x, b.y), b.z);
}
void solve() {
  long long n;
  cin >> n;
  vector<pt> a(n);
  for (long long(i) = 0; (i) < (n); ++(i)) cin >> a[i].x >> a[i].y >> a[i].z;
  for (long long(i) = 0; (i) < (n); ++(i)) a[i].id = i;
  sort((a).begin(), (a).end());
  vector<pt> nxta;
  vector<pair<long long, long long>> res;
  for (long long(i) = 0; (i) < ((long long)(a).size()); ++(i)) {
    if (i + 1 == (long long)(a).size()) {
      nxta.push_back(a[i]);
      break;
    }
    bool good = false;
    if (a[i].x == a[i + 1].x) {
      if (a[i].y == a[i + 1].y) {
        good = true;
      }
    }
    if (good) {
      res.push_back({a[i].id, a[i + 1].id});
      i++;
    } else {
      nxta.push_back(a[i]);
    }
  }
  a = nxta;
  nxta.clear();
  for (long long(i) = 0; (i) < ((long long)(a).size()); ++(i)) {
    if (i + 1 == (long long)(a).size()) {
      nxta.push_back(a[i]);
      break;
    }
    bool good = false;
    if (a[i].x == a[i + 1].x) {
      good = true;
    }
    if (good) {
      res.push_back({a[i].id, a[i + 1].id});
      i++;
    } else {
      nxta.push_back(a[i]);
    }
  }
  a = nxta;
  nxta.clear();
  for (long long(i) = 0; (i) < ((long long)(a).size()); ++(i)) {
    if (i + 1 == (long long)(a).size()) {
      nxta.push_back(a[i]);
      break;
    }
    bool good = true;
    if (good) {
      res.push_back({a[i].id, a[i + 1].id});
      i++;
    } else {
      nxta.push_back(a[i]);
    }
  }
  for (auto i : res) {
    cout << i.first + 1 << ' ' << i.second + 1 << '\n';
  }
}
