#include <bits/stdc++.h>
using namespace std;
int n;
struct P {
  int x, y, z, id;
  bool operator<(const P &a) const {
    if (x != a.x) return x < a.x;
    if (y != a.y) return y < a.y;
    return z < a.z;
  }
} a[50005];
vector<pair<int, int> > ans;
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++)
    scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z), a[i].id = i;
  sort(a + 1, a + n + 1);
  int top = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (top && a[i].x == a[top].x && a[i].y == a[top].y)
      ans.push_back(pair<int, int>(a[i].id, a[top--].id));
    else
      a[++top] = a[i];
  n = top;
  top = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (top && a[i].x == a[top].x)
      ans.push_back(pair<int, int>(a[i].id, a[top--].id));
    else
      a[++top] = a[i];
  n = top;
  top = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (top)
      ans.push_back(pair<int, int>(a[i].id, a[top--].id));
    else
      a[++top] = a[i];
  for (int i = (int)(0); i <= (int)(ans.size() - 1); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
}
