#include <bits/stdc++.h>
using namespace std;
long long MPOW(long long a, long long b, long long m) {
  if (b == 0) return 1;
  long long x = MPOW(a, b / 2, m);
  x = (x * x) % m;
  if (b % 2 == 1) x = (x * a) % m;
  return x;
}
long long MINV(long long a, long long m) { return MPOW(a, m - 2, m); }
long long GCD(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}
long long LCM(long long x, long long y) { return (x * y) / GCD(x, y); }
inline void swap(long long &a, long long &b) {
  long long temp = a;
  a = b;
  b = temp;
}
inline long long max(long long a, long long b) { return ((a > b) ? a : b); }
bool sortbythis(const pair<long long, pair<long long, long long>> a,
                const pair<long long, pair<long long, long long>> b) {
  if (a.first < b.first)
    return true;
  else if (a.first > b.first)
    return false;
  else {
    if ((a.second).first < (b.second).first)
      return true;
    else if ((a.second).first > (b.second).first)
      return false;
    else
      return ((a.second).second <= (b.second).second);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<pair<long long, pair<long long, long long>>> v(n), v1, v2;
  map<pair<long long, pair<long long, long long>>, long long> m;
  for (long long i = 0; i < n; ++i) {
    cin >> v[i].first >> (v[i].second).first >> (v[i].second).second;
    m[v[i]] = i + 1;
  }
  sort(v.begin(), v.end(), sortbythis);
  for (long long i = 0; i < n; ++i) {
    if (i < n - 1) {
      if (v[i].first == v[i + 1].first &&
          (v[i].second).first == (v[i + 1].second).first) {
        cout << m[v[i]] << ' ' << m[v[i + 1]] << '\n';
        i++;
      } else
        v1.push_back(v[i]);
    } else
      v1.push_back(v[i]);
  }
  n = v1.size();
  for (long long i = 0; i < n; ++i) {
    if (i < n - 1) {
      if (v1[i].first == v1[i + 1].first) {
        cout << m[v1[i]] << ' ' << m[v1[i + 1]] << '\n';
        i++;
      } else
        v2.push_back(v1[i]);
    } else
      v2.push_back(v1[i]);
  }
  n = v2.size();
  for (long long i = 0; i < n; i += 2)
    cout << m[v2[i]] << ' ' << m[v2[i + 1]] << '\n';
  return 0;
}
