#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(0));
long long const inf = 1e9 + 10;
long long const INF = 1e18;
long long mod = 998244353;
int n;
bool used[2020];
int first[100100];
int second[100100];
int z[100100];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> first[i] >> second[i] >> z[i];
  }
  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    used[i] = true;
    long long mini = inf;
    int numb = -1;
    for (int j = i + 1; j < n; j++) {
      if (!used[j]) {
        if (mini > abs(first[i] - first[j]) + abs(second[i] - second[j]) +
                       abs(z[i] - z[j])) {
          mini = abs(first[i] - first[j]) + abs(second[i] - second[j]) +
                 abs(z[i] - z[j]);
          numb = j;
        }
      }
    }
    cout << i + 1 << " " << numb + 1 << "\n";
    used[numb] = true;
  }
  return 0;
}
