#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int T = 1 << 11;
int MAX = 100009;
vector<int> parent(MAX, -1);
vector<int> rang(MAX, 0);
const int INF = 100000000;
void solve() {
  int n, x, y, z;
  cin >> n;
  vector<tuple<int, int, int>> mas(0);
  map<tuple<int, int, int>, int> make_pair;
  for (long long i = 0; i < n; i++) {
    cin >> x >> y >> z;
    mas.push_back({x, y, z});
    make_pair[{x, y, z}] = i;
  }
  sort(mas.begin(), mas.end());
  while (true) {
    auto t = mas[0];
    x = get<0>(mas[1]);
    int i = 1;
    while (i < mas.size() - 1 && get<1>(mas[i + 1]) <= get<1>(mas[0]) &&
           get<0>(mas[i + 1]) == x) {
      i++;
    }
    y = get<1>(mas[i]);
    while (i < mas.size() - 1 && get<0>(mas[i]) == get<0>(mas[i + 1]) &&
           get<1>(mas[i]) == get<1>(mas[i + 1])) {
      i++;
    }
    while (i - 1 >= 1 && get<2>(mas[i - 1]) >= get<2>(mas[0]) &&
           get<1>(mas[i - 1]) == y) {
      i--;
    }
    vector<tuple<int, int, int>> mas1(0);
    for (long long j = 1; j < mas.size(); j++) {
      if (j != i) mas1.push_back(mas[j]);
    }
    cout << make_pair[mas[0]] + 1 << " " << make_pair[mas[i]] + 1 << "\n";
    mas.clear();
    mas = mas1;
    if (mas.size() == 0) break;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q = 1;
  while (q--) {
    solve();
  }
}
