#include <bits/stdc++.h>
using namespace std;
template <typename T>
void prn(T first) {
  cout << first << "\n";
}
bool mycomp(vector<int>& a, vector<int>& b) {
  if (a[0] == b[0]) {
    if (a[1] == b[1]) {
      return a[2] < b[2];
    } else {
      return a[1] < b[1];
    }
  } else {
    return a[0] < b[0];
  }
}
int main() {
  int n, x, y, z, alive;
  cin >> n;
  vector<vector<int>> arr, temp;
  for (int i = 0; i < n; ++i) {
    cin >> x >> y >> z;
    arr.push_back(vector<int>{x, y, z, i + 1});
  }
  sort(arr.begin(), arr.end(), mycomp);
  for (int i = 0; i < arr.size(); i++) {
    if (i + 1 < n && arr[i][0] == arr[i + 1][0] && arr[i][1] == arr[i + 1][1]) {
      cout << arr[i][3] << " " << arr[i + 1][3] << endl;
      i++;
    } else {
      temp.push_back(arr[i]);
    }
  }
  arr = temp;
  temp.clear();
  for (int i = 0; i < arr.size(); i++) {
    if (i + 1 < n && arr[i][0] == arr[i + 1][0]) {
      cout << arr[i][3] << " " << arr[i + 1][3] << endl;
      i++;
    } else {
      temp.push_back(arr[i]);
    }
  }
  arr = temp;
  temp.clear();
  for (int i = 0; i < arr.size(); i += 2) {
    cout << arr[i][3] << " " << arr[i + 1][3] << endl;
  }
  return 0;
}
