#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  map<pair<long long int, long long int>,
      vector<pair<long long int, long long int> > >
      mp;
  map<long long int, vector<pair<long long int, long long int> > > mp2;
  vector<pair<long long int, long long int> > v;
  for (long long int i = 1; i < n + 1; i++) {
    long long int x, y, z;
    cin >> x >> y >> z;
    mp[{x, y}].push_back({z, i});
  }
  for (auto &it : mp) {
    sort((it.second).begin(), (it.second).end());
    for (long long int i = 0; i < it.second.size() - 1; i += 2)
      cout << it.second[i].second << " " << it.second[i + 1].second << endl;
    if (it.second.size() % 2)
      mp2[it.first.first].push_back({it.first.second, it.second.back().second});
  }
  for (auto &it : mp2) {
    sort((it.second).begin(), (it.second).end());
    for (long long int i = 0; i < it.second.size() - 1; i += 2)
      cout << it.second[i].second << " " << it.second[i + 1].second << endl;
    if (it.second.size() % 2) v.push_back({it.first, it.second.back().second});
  }
  for (long long int i = 0; i < v.size(); i += 2)
    cout << v[i].second << " " << v[i + 1].second << endl;
}
