#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int arr[N];
bool vis[N] = {0};
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  map<int, map<int, vector<pair<int, int>>>> pts;
  for (int i = 0; i < n; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    pts[x][y].push_back({z, i});
  }
  vector<pair<int, int>> res, remz2;
  for (auto x : pts) {
    vector<pair<int, int>> remz;
    for (auto &y : x.second) {
      sort((y.second).begin(), y.second.end());
      for (int i = 1; i < (int)(y.second).size(); i += 2)
        res.push_back({y.second[i].second, y.second[i - 1].second});
      if ((int)(y.second).size() & 1) {
        remz.push_back(y.second.back());
      }
    }
    for (int i = 1; i < (int)(remz).size(); i += 2)
      res.push_back({remz[i].second, remz[i - 1].second});
    if ((int)(remz).size() & 1) {
      remz2.push_back(remz.back());
    }
  }
  for (int i = 1; i < (int)(remz2).size(); i += 2)
    res.push_back({remz2[i].second, remz2[i - 1].second});
  for (auto r : res) cout << r.first + 1 << " " << r.second + 1 << '\n';
  return 0;
}
