#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
  c h, n;
};
template <class c>
rge<c> range(c h, c n) {
  return rge<c>{h, n};
}
template <class c>
auto dud(c *r) -> decltype(cerr << *r);
template <class c>
char dud(...);
struct muu {
  template <class c>
  muu &operator<<(const c &) {
    return *this;
  }
};
const int MN = 1e3 + 44;
pair<int, int> coo[MN];
int col[MN];
int n;
int det(int a, int b, int c) {
  return (coo[a].first - coo[b].first) * (coo[a].second - coo[c].second) -
         (coo[a].second - coo[b].second) * (coo[a].first - coo[c].first);
}
bool inside(int a, int b, int c, int i) {
  return abs(det(a, b, i)) + abs(det(b, c, i)) + abs(det(c, a, i)) ==
         abs(det(a, b, c));
}
vector<pair<int, int> > ans;
void go(int a, int b, int c) {
  vector<int> points;
  for (int i = 0; i < n; ++i)
    if (i != a && i != b && i != c && inside(a, b, c, i)) points.push_back(i);
  muu() << __FUNCTION__ << "#" << 60 << ": "
        << "["
           "coo"
           "["
           "a"
           ": "
        << (a)
        << "] "
           ": "
        << coo[a]
        << "] "
           "["
           "coo"
           "["
           "b"
           ": "
        << (b)
        << "] "
           ": "
        << coo[b]
        << "] "
           "["
           "coo"
           "["
           "c"
           ": "
        << (c)
        << "] "
           ": "
        << coo[c]
        << "] "
           "["
           "points"
           ": "
        << (points) << "] ";
  int more = (col[a] + col[b] + col[c]) >= 2;
  int oth = col[a] != more ? a : (col[b] != more ? b : c);
  assert(col[oth] != more);
  for (int x : points) {
    if (col[x] != more) {
      muu() << __FUNCTION__ << "#" << 66 << ": "
            << "["
               "col"
               "["
               "x"
               ": "
            << (x)
            << "] "
               ": "
            << col[x]
            << "] "
               "["
               "col"
               "["
               "oth"
               ": "
            << (oth)
            << "] "
               ": "
            << col[oth]
            << "] "
               "["
               "more"
               ": "
            << (more) << "] ";
      ans.emplace_back(x, oth);
      go(a, b, x);
      go(b, c, x);
      go(c, a, x);
      return;
    }
  }
  int m = col[a] == more ? a : b;
  for (int x : points) ans.emplace_back(m, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d%d%d", &coo[i].first, &coo[i].second, col + i);
  vector<int> order;
  for (int i = 0; i < n; ++i) order.push_back(i);
  sort(order.begin(), order.end(),
       [](int i, int j) { return coo[i] < coo[j]; });
  vector<int> up, down;
  for (int i : order) {
    while (up.size() >= 2u && det(up.back(), up[up.size() - 2], i) >= 0)
      up.pop_back();
    while (down.size() >= 2u && det(down.back(), down[down.size() - 2], i) <= 0)
      down.pop_back();
    up.push_back(i);
    down.push_back(i);
  }
  reverse(down.begin(), down.end());
  up.pop_back();
  down.pop_back();
  vector<int> hull = up;
  for (int y : down) hull.push_back(y);
  muu() << __FUNCTION__ << "#" << 100 << ": "
        << "["
           "hull"
           ": "
        << (hull) << "] ";
  vector<int> last_one, last_zero;
  int H = hull.size();
  for (int i = 0; i < H; ++i) {
    int c1 = col[hull[i]];
    int c2 = col[hull[(i + 1) % H]];
    if (c1 == 0 && c2 == 1)
      last_zero.push_back(i);
    else if (c1 == 1 && c2 == 0)
      last_one.push_back(i);
  }
  muu() << __FUNCTION__ << "#" << 111 << ": "
        << "["
           "last_one"
           ": "
        << (last_one)
        << "] "
           "["
           "last_zero"
           ": "
        << (last_zero) << "] ";
  if (last_one.size() >= 2u) {
    printf("Impossible\n");
    return 0;
  }
  if (last_one.size() == 1) {
    for (int i : hull)
      if (i != hull[last_one[0]] && i != hull[last_zero[0]])
        go(i, hull[last_one[0]], hull[last_zero[0]]);
    for (int i = 0; i < H; ++i)
      if (col[hull[i]] == col[hull[(i + 1) % H]])
        ans.emplace_back(hull[i], hull[(i + 1) % H]);
  } else {
    int oth = -1;
    for (int i = 0; i < n; ++i)
      if (col[i] != col[hull[0]]) oth = i;
    if (oth == -1)
      for (int i = 1; i < n; ++i) ans.emplace_back(0, i);
    else {
      for (int i = 0; i < H; ++i) go(hull[i], hull[(i + 1) % H], oth);
      for (int i = 0; i < H - 1; ++i) ans.emplace_back(hull[i], hull[i + 1]);
    }
  }
  printf("%d\n", (int)ans.size());
  for (auto x : ans) printf("%d %d\n", x.first, x.second);
}
