#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
char en = '\n';
long long inf = 1e16;
long long mod = 1e9 + 7;
long long power(long long x, long long n, long long mod) {
  long long res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
struct node {
  long long x, y, z;
  long long indx;
};
bool compx(node &a, node &b) { return a.x < b.x; }
bool compy(node &a, node &b) { return a.y < b.y; }
bool compz(node &a, node &b) { return a.z < b.z; }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  node arr[n + 5];
  map<long long, vector<node>> par;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i].x >> arr[i].y >> arr[i].z;
    arr[i].indx = i;
    par[arr[i].z].push_back(arr[i]);
  }
  vector<node> temp2;
  for (auto &it : par) {
    vector<node> curr = it.second;
    map<long long, vector<node>> par2;
    for (node &x1 : curr) {
      par2[x1.x].push_back(x1);
    }
    vector<node> temp;
    for (auto &it2 : par2) {
      vector<node> &curr = it2.second;
      sort(curr.begin(), curr.end(), compy);
      while (curr.size() >= 2) {
        cout << curr.back().indx << " ";
        curr.pop_back();
        cout << curr.back().indx << " ";
        curr.pop_back();
        cout << en;
      }
      if (curr.size()) temp.push_back(curr[0]);
    }
    curr = temp;
    temp.clear();
    sort(curr.begin(), curr.end(), compx);
    while (curr.size() >= 2) {
      cout << curr.back().indx << " ";
      curr.pop_back();
      cout << curr.back().indx << " ";
      curr.pop_back();
      cout << en;
    }
    if (curr.size()) temp2.push_back(curr[0]);
  }
  vector<node> curr = temp2;
  sort(curr.begin(), curr.end(), compz);
  while (curr.size() >= 2) {
    cout << curr.back().indx << " ";
    curr.pop_back();
    cout << curr.back().indx << " ";
    curr.pop_back();
    cout << en;
  }
  return 0;
}
