#include <bits/stdc++.h>
using namespace std;
int p[2001][3];
int solve(vector<int> ids, int k) {
  if (k == 3) return ids[0];
  map<int, vector<int>> mp;
  for (int i = 0; i < ids.size(); i++) {
    mp[p[ids[i]][k]].push_back(ids[i]);
  }
  vector<int> a;
  for (auto x : mp) {
    int cur = solve(x.second, k + 1);
    if (cur != -1) a.push_back(cur);
  }
  for (int i = 0; (i + 1) < a.size(); i += 2) {
    cout << a[i] + 1 << " " << a[i + 1] + 1 << endl;
  }
  if (a.size() % 2 == 0) return -1;
  return a.back();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        cin >> p[i][j];
      }
    }
    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);
    solve(ids, 0);
  }
  return 0;
}
