#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 50;
int n, m, vis[MAX];
struct P {
  int x, y, col, id;
  P(int x = 0, int y = 0, int col = 0, int id = 0)
      : x(x), y(y), col(col), id(id) {}
  friend inline P operator-(const P &a, const P &b) {
    return P(a.x - b.x, a.y - b.y);
  }
  friend inline int operator*(const P &a, const P &b) {
    return a.x * b.y - a.y * b.x;
  }
} p[MAX], q[MAX];
vector<pair<int, int>> ans;
inline void add(int x, int y) { ans.push_back({x, y}); }
inline bool in(P a, P b, P c, P d) {
  return (a - d) * (b - d) > 0 && (b - d) * (c - d) > 0 &&
         (c - d) * (a - d) > 0;
}
void solve(P a, P b, P c) {
  for (int i = 1; i <= n; i++)
    if (in(a, b, c, p[i]) && p[i].col != a.col) {
      add(p[i].id, c.id);
      solve(c, p[i], b);
      solve(a, b, p[i]);
      solve(p[i], c, a);
      return;
    }
  vector<P> vec;
  for (int i = 1; i <= n; i++)
    if (in(a, b, c, p[i])) add(a.id, p[i].id);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y >> p[i].col, p[i].id = i;
  if (n == 2) {
    if (p[1].col ^ p[2].col)
      puts("1\n1 2");
    else
      puts("0");
    return 0;
  }
  sort(p + 1, p + n + 1, [&](const P &a, const P &b) {
    return a.x < b.x || (a.x == b.x && a.y < b.y);
  });
  sort(p + 2, p + n + 1,
       [&](const P &a, const P &b) { return (a - p[1]) * (b - p[1]) > 0; });
  q[m = 1] = p[1];
  for (int i = 2; i <= n; i++) {
    while (m >= 2 && (p[i] - q[m - 1]) * (q[m] - q[m - 1]) > 0) --m;
    q[++m] = p[i];
  }
  int fir[2] = {0, 0}, lst[2] = {0, 0}, cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (q[i].col != q[i % m + 1].col) {
      ++cnt;
      if (cnt > 2) {
        puts("Impossible");
        return 0;
      }
      if (!fir[0]) {
        fir[0] = i, fir[1] = i % m + 1;
        if (q[i].col != q[(i == 1) ? m : (i - 1)].col)
          lst[1] = i, lst[0] = i % m + 1;
      } else
        lst[1] = i, lst[0] = i % m + 1;
    }
  }
  for (int i = 1; i <= m; i++) vis[q[i].id] = 1;
  if (!cnt) {
    int tag = 0;
    for (int i = 1; i <= n; i++)
      if (!vis[i] && p[i].col != q[1].col) {
        for (int j = 1; j <= m; j++) {
          if (j != m) add(q[j].id, q[j + 1].id);
          solve(q[j], q[j % m + 1], p[i]);
        }
        tag = 1;
        break;
      }
    if (!tag)
      for (int i = 1; i < n; i++) add(p[i].id, p[n].id);
  } else {
    for (int i = fir[1]; i != lst[1]; i = i % m + 1)
      add(q[i].id, q[i % m + 1].id), solve(q[i], q[i % m + 1], q[lst[0]]);
    for (int i = lst[0]; i != fir[0]; i = i % m + 1)
      add(q[i].id, q[i % m + 1].id), solve(q[i], q[i % m + 1], q[fir[1]]);
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first - 1 << ' ' << ans[i].second - 1 << '\n';
}
