#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
const int n = (1e6) + 10;
const long long inf = 1e12;
vector<pair<int, int>> g[n];
vector<pair<int, int>> weight[n];
int numofvertex = -1;
bool f(long long w) {
  set<pair<int, int>> s;
  s.insert(make_pair(1, 0));
  long long dest[numofvertex + 1];
  for (int i = 0; i < numofvertex + 1; i++) {
    dest[i] = inf;
  }
  dest[1] = 0;
  while (!s.empty()) {
    int from = (*s.begin()).first;
    s.erase(s.begin());
    for (int i = 0; i < g[from].size(); i++) {
      int to = g[from][i].first;
      int time = g[from][i].second;
      int to_weight = weight[from][i].second;
      if ((dest[to] > dest[from] + time) && (to_weight >= w)) {
        dest[to] = dest[from] + time;
        s.erase(make_pair(to, dest[to]));
        s.insert(make_pair(to, dest[to]));
      }
    }
  }
  if (dest[numofvertex] <= 1440) {
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int c[n];
  set<int> ss;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    ss.insert(i);
  }
  int f = 0, s = 0;
  while (!ss.empty()) {
    f = *ss.begin();
    ss.erase(f);
    s = *ss.begin();
    for (int i = 0; i < n; i++) {
      if (ss.count(i)) {
        if ((i == f || i == s)) continue;
        if ((min(a[f], a[s]) <= a[i]) && (a[i] <= max(a[f], a[s])) &&
            (min(b[f], b[s]) <= b[i]) && (b[i] <= max(b[f], b[s])) &&
            (min(c[f], c[s]) <= c[i]) && (c[i] <= max(c[f], c[s]))) {
          s = i;
        }
      }
    }
    cout << f + 1 << " " << s + 1 << endl;
    ss.erase(s);
  }
}
