#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5;
int n;
bool del[N];
struct Point {
  int x, y, z, id;
  Point(int x = 0, int y = 0, int z = 0, int id = 0)
      : x(x), y(y), z(z), id(id) {}
} a[N], b[N], c[N], d[N];
bool cmp1(Point A, Point B) {
  if (A.x != B.x)
    return A.x < B.x;
  else {
    if (A.y != B.y)
      return A.y < B.y;
    else
      return A.z < B.z;
  }
}
bool cmp2(Point A, Point B) { return A.y < B.y; }
bool cmp3(Point A, Point B) { return A.z < B.z; }
vector<Point> vec;
vector<pair<int, int> > ans;
map<pair<int, int>, set<int> > mm;
map<pair<int, pair<int, int> >, int> mm2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].z;
    a[i].id = i;
    b[i] = c[i] = d[i] = a[i];
    mm[{a[i].x, a[i].y}].insert(a[i].z);
    mm2[{a[i].x, {a[i].y, a[i].z}}] = a[i].id;
  }
  sort(b + 1, b + n + 1, cmp1);
  sort(c + 1, c + n + 1, cmp2);
  sort(d + 1, d + n + 1, cmp3);
  for (int i = 1; i <= n; i++)
    vec.push_back(Point(b[i].x, b[i].y, b[i].z, b[i].id));
  for (int i = 1; i <= n; i++) {
    if (del[i]) continue;
    long long Min = 1e18;
    int pos = i;
    for (int j = i + 1; j <= n; j++) {
      if (!del[j]) {
        long long dist = 1LL * (a[i].x - a[j].x) * (a[i].x - a[j].x) +
                         1LL * (a[i].y - a[j].y) * (a[i].y - a[j].y) +
                         1LL * (a[i].z - a[j].z) * (a[i].z - a[j].z);
        if (dist < Min) {
          Min = dist;
          pos = j;
        }
      }
    }
    del[pos] = true;
    ans.push_back({i, pos});
  }
  for (auto i : ans) cout << i.first << " " << i.second << "\n";
  return 0;
}
