#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  a = a % 998244353;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % 998244353;
      b--;
    }
    a = (a * a) % 998244353;
    b >>= 1;
  }
  return res;
}
long long fermat_inv(long long y) { return power(y, 998244353 - 2); }
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T--) {
    int n;
    cin >> n;
    vector<pair<long long, pair<long long, pair<long long, int>>>> co;
    for (int i = 0; i < n; i++) {
      long long x, y, z;
      cin >> x >> y >> z;
      co.push_back(make_pair(x, make_pair(y, make_pair(z, i + 1))));
    }
    sort(co.begin(), co.end());
    vector<bool> aux(n, false);
    for (int i = 0; i < n - 1; i++) {
      if (co[i].first == co[i + 1].first &&
          co[i].second.first == co[i + 1].second.first) {
        cout << co[i].second.second.second << " "
             << co[i + 1].second.second.second << "\n";
        aux[i] = aux[i + 1] = true;
        i++;
      }
    }
    for (int i = 0; i < n - 1; i++) {
      if (aux[i] == true) continue;
      int j = i + 1;
      while (j < n && co[i].first == co[j].first) {
        if (aux[j] == true) {
          j++;
          continue;
        }
        cout << co[i].second.second.second << " " << co[j].second.second.second
             << "\n";
        aux[i] = aux[j] = true;
        break;
      }
      i = j - 1;
    }
    for (int i = 0; i < n - 1; i++) {
      if (aux[i] == true) continue;
      int j = i + 1;
      while (j < n && aux[j] == true) {
        j++;
      }
      cout << co[i].second.second.second << " " << co[j].second.second.second
           << "\n";
      aux[i] = aux[j] = true;
      i = j;
    }
  }
}
