#include <bits/stdc++.h>
using namespace std;
int a[1000001], b[1000000];
vector<pair<pair<int, int>, pair<int, int> > > v;
vector<int> v1, v2;
int main() {
  ios_base::sync_with_stdio(false);
  int j, n, m, k, m1, m2, a1, a2, l, t, cnt = 0, mn = INT_MAX, h = 0,
                                        mod = 1e9 + 7, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> j >> k >> l;
    v.push_back({{j, k}, {l, i}});
  }
  sort(v.begin(), v.end());
  v.push_back({{INT_MAX, 0}, {0, 0}});
  for (i = 0; i < n; i++) {
    for (j = i; j < n; j++) {
      if (v[j + 1].first.first != v[i].first.first) break;
    }
    k = i;
    v1.clear();
    while (k <= j) {
      if (k != j && v[k].first.second == v[k + 1].first.second) {
        cout << v[k].second.second << ' ' << v[k + 1].second.second << endl;
        k += 2;
      } else {
        v1.push_back(v[k].second.second);
        k++;
      }
    }
    if (v1.size() > 1)
      for (k = 0; k < (v1.size() / 2) * 2; k += 2)
        cout << v1[k] << ' ' << v1[k + 1] << endl;
    if (v1.size() % 2) v2.push_back(v1[v1.size() - 1]);
    i = j;
  }
  for (i = 0; i < v2.size(); i += 2) cout << v2[i] << ' ' << v2[i + 1] << endl;
  return 0;
}
