#include <bits/stdc++.h>
using namespace std;
long long solve(vector<pair<long long, long long> >& look) {
  long long i, tot = (long long)look.size();
  for (i = 0; i < (tot / 2) * 2; i += 2)
    cout << look[i].second << " " << look[i + 1].second << endl;
  if (tot % 2 == 1) return look[tot - 1].second;
  return -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, i;
  cin >> n;
  map<long long, map<long long, vector<pair<long long, long long> > > > look;
  for (i = 0; i < n; i += 1) {
    long long x, y, z;
    cin >> x >> y >> z;
    if (look[x].find(y) == look[x].end())
      look[x][y] = vector<pair<long long, long long> >();
    look[x][y].push_back(make_pair(z, i + 1));
  }
  map<long long,
      map<long long, vector<pair<long long, long long> > > >::iterator it;
  map<long long, vector<pair<long long, long long> > >::iterator it1;
  map<long long, vector<pair<long long, long long> > > look1;
  for (it = look.begin(); it != look.end(); it++) {
    for (it1 = it->second.begin(); it1 != it->second.end(); it1++) {
      sort(it1->second.begin(), it1->second.end());
      long long temp = solve(it1->second);
      if (temp != -1) look1[it->first].push_back(make_pair(it1->first, temp));
    }
  }
  vector<long long> ultima;
  for (it1 = look1.begin(); it1 != look1.end(); it1++) {
    long long temp = solve(it1->second);
    if (temp != -1) ultima.push_back(temp);
  }
  long long tot = (long long)ultima.size();
  for (i = 0; i < tot; i += 2)
    cout << ultima[i] << " " << ultima[i + 1] << endl;
  return 0;
}
