#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  map<pair<long long, long long>, set<pair<long long, long long>>> mp;
  for (long long i = 1; i <= n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    mp[{x, y}].insert({z, i});
  }
  map<long long, set<pair<long long, long long>>> mp2;
  for (auto &k : mp) {
    while (k.second.size() > 1) {
      cout << (*k.second.begin()).second << " ";
      k.second.erase(k.second.begin());
      cout << (*k.second.begin()).second << endl;
      k.second.erase(k.second.begin());
    }
    if (k.second.size() == 1)
      mp2[k.first.first].insert({k.first.second, (*k.second.begin()).second});
  }
  vector<long long> ind;
  for (auto &k : mp2) {
    while (k.second.size() > 1) {
      cout << (*k.second.begin()).second << " ";
      k.second.erase(k.second.begin());
      cout << (*k.second.begin()).second << endl;
      k.second.erase(k.second.begin());
    }
    if (k.second.size() == 1) ind.push_back((*k.second.begin()).second);
  }
  for (long long i = 0; (unsigned)i < ind.size(); i += 2) {
    cout << ind[i] << " " << ind[i + 1] << endl;
  }
}
