#include <bits/stdc++.h>
using namespace std;
int solve1(vector<vector<int>> &p, vector<int> ind, int d) {
  if (d == 3) return ind[0];
  map<int, vector<int>> make_pair;
  for (auto i : ind) {
    make_pair[p[i][d]].push_back(i);
  }
  vector<int> a;
  for (auto &i : make_pair) {
    int temp = solve1(p, i.second, d + 1);
    if (temp != -1) {
      a.push_back(temp);
    }
  }
  int len = ((int)(a).size());
  for (int i = 0; i + 1 < len; i += 2) {
    cout << a[i] + 1 << " " << a[i + 1] + 1 << "\n";
  }
  return len % 2 ? a.back() : -1;
}
void solve() {
  int n;
  cin >> n;
  vector<vector<int>> p(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) cin >> p[i][j];
  }
  vector<int> ind(n);
  iota(ind.begin(), ind.end(), 0);
  solve1(p, ind, 0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
}
