#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 51000;
int X[N_MAX], Y[N_MAX], Z[N_MAX];
bool vis[N_MAX];
bool ff(int i, int j) {
  if (X[i] != X[j]) return X[i] < X[j];
  if (Y[i] != Y[j]) return Y[i] < Y[j];
  return Z[i] < Z[j];
}
int main() {
  int n;
  cin >> n;
  vector<int> P;
  for (int i = 1; i <= n; i++) {
    cin >> X[i] >> Y[i] >> Z[i];
    P.push_back(i);
  }
  sort(P.begin(), P.end(), ff);
  for (int i = 0; i < n - 1; i++) {
    if (vis[P[i]]) continue;
    if (X[P[i]] == X[P[i + 1]] and Y[P[i]] == Y[P[i + 1]]) {
      vis[P[i]] = 1;
      vis[P[i + 1]] = 1;
      cout << P[i] << " " << P[i + 1] << endl;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (vis[P[i]]) continue;
    if (X[P[i]] != X[P[i + 1]]) continue;
    int j = i + 1;
    while (vis[P[j]] and j < n) {
      j++;
    }
    if (j == n or X[P[i]] != X[P[j]]) continue;
    vis[P[i]] = 1;
    vis[P[j]] = 1;
    cout << P[i] << " " << P[j] << endl;
  }
  for (int i = 0; i < n - 1; i++) {
    if (vis[P[i]]) continue;
    int j = i + 1;
    while (vis[P[j]] and j < n) {
      j++;
    }
    vis[P[i]] = 1;
    vis[P[j]] = 1;
    cout << P[i] << " " << P[j] << endl;
  }
  return 0;
}
