#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, pair<int, int>>> v1, v2, v3;
bool visit[50005];
int n;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    v1.push_back({{x, y}, {z, i + 1}});
  }
  sort(v1.begin(), v1.end());
  for (int i = 0; i < n - 1; i++)
    if (!visit[v1[i].second.second]) {
      if (v1[i].first == v1[i + 1].first) {
        cout << v1[i].second.second << ' ' << v1[i + 1].second.second << '\n';
        visit[v1[i + 1].second.second] = visit[v1[i].second.second] = 1;
      } else
        v2.push_back(v1[i]);
    }
  if (!visit[v1[n - 1].second.second]) v2.push_back(v1[n - 1]);
  if (!v2.size()) return 0;
  for (int i = 0; i < v2.size() - 1; i++)
    if (!visit[v2[i].second.second]) {
      if (v2[i].first.first == v2[i + 1].first.first) {
        cout << v2[i].second.second << ' ' << v2[i + 1].second.second << '\n';
        visit[v2[i + 1].second.second] = visit[v2[i].second.second] = 1;
      } else
        v3.push_back(v2[i]);
    }
  if (!visit[v2[v2.size() - 1].second.second]) v3.push_back(v2[v2.size() - 1]);
  if (!v3.size()) return 0;
  for (int i = 0; i < v3.size() - 1; i++)
    if (!visit[v3[i].second.second]) {
      cout << v3[i].second.second << ' ' << v3[i + 1].second.second << '\n';
      visit[v3[i + 1].second.second] = visit[v3[i].second.second] = 1;
    }
  return 0;
}
