#include <bits/stdc++.h>
using namespace std;
inline void out(int x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
inline long long gi() {
  long long x = 0, q = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') q = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
  return q * x;
}
const int N = 1e5 + 5;
const int M = 1e2 + 5;
map<pair<int, int>, int> m;
set<int> de;
int x[N], y[N], z[N], id[N], n, pos;
struct Edge {
  int to, next;
  int w;
} edge[M];
int tot, head[N];
void _init() {
  tot = 0;
  for (int i = 0; i <= n; i++) head[i] = -1;
}
void add(int u, int v, int w) {
  edge[tot].to = v, edge[tot].w = w, edge[tot].next = head[u], head[u] = tot++;
}
int cmp(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];
}
void init() {
  n = gi();
  for (int i = 1; i <= n; i++) {
    x[i] = gi(), y[i] = gi(), z[i] = gi();
    id[i] = i;
  }
  sort(id + 1, id + 1 + n, cmp);
}
void dbug() { cout << "dd" << endl; }
int main() {
  init();
  for (int i = 1; i <= n; i++) {
    pos = id[i];
    if (de.count(pos)) continue;
    pair<int, int> p(x[pos], y[pos]);
    if (m.count(p)) {
      de.insert(pos);
      de.insert(m[p]);
      printf("%d %d\n", pos, m[p]);
      m.erase(p);
    } else
      m[p] = pos;
  }
  int tmp;
  m.clear();
  for (int i = 1; i <= n; i++) {
    pos = id[i];
    if (de.count(pos)) continue;
    pair<int, int> p(x[pos], 0);
    if (m.count(p)) {
      de.insert(pos);
      de.insert(m[p]);
      printf("%d %d\n", pos, m[p]);
      m.erase(p);
    } else
      m[p] = pos;
  }
  int vtt;
  m.clear();
  for (int i = 1; i <= n; i++) {
    pos = id[i];
    if (de.count(pos)) continue;
    pair<int, int> p(0, 0);
    if (m.count(p)) {
      de.insert(pos);
      de.insert(m[p]);
      printf("%d %d\n", pos, m[p]);
      m.erase(p);
    } else
      m[p] = pos;
  }
  return 0;
}
