#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int vis[N];
map<pair<int, int>, vector<pair<int, int> > > m1;
map<int, vector<pair<int, int> > > m2;
vector<pair<int, int> > m3;
int x[N], y[N], z[N];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i];
  for (int i = 1; i <= n; i++) m1[{x[i], y[i]}].push_back({z[i], i});
  for (auto p : m1) {
    auto v = p.second;
    sort(v.begin(), v.end());
    for (int i = 0; i + 1 < (int)v.size(); i += 2) {
      int a = v[i].second, b = v[i + 1].second;
      cout << a << ' ' << b << endl;
      vis[a] = vis[b] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] == 0) m2[x[i]].push_back({y[i], i});
  for (auto p : m2) {
    auto v = p.second;
    sort(v.begin(), v.end());
    for (int i = 0; i + 1 < (int)v.size(); i += 2) {
      int a = v[i].second, b = v[i + 1].second;
      cout << a << ' ' << b << endl;
      vis[a] = vis[b] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] == 0) m3.push_back({x[i], i});
  auto v = m3;
  sort(v.begin(), v.end());
  for (int i = 0; i + 1 < (int)v.size(); i += 2) {
    int a = v[i].second, b = v[i + 1].second;
    cout << a << ' ' << b << endl;
    vis[a] = vis[b] = 1;
  }
}
