#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct point {
  long long x, y;
  int c, id;
  point() {}
  point(long long x, long long y, int c = -1, int id = -1)
      : x(x), y(y), c(c), id(id) {}
  inline point operator-() const { return point(-x, -y); }
  inline point operator+(const point &pt) const {
    return point(x + pt.x, y + pt.y);
  }
  inline point operator-(const point &pt) const {
    return point(x - pt.x, y - pt.y);
  }
  inline point operator*(const long long &a) const {
    return point(x * a, y * a);
  }
  inline point operator/(const long long &a) const {
    return point(x / a, y / a);
  }
  inline long long operator*(const point &pt) const {
    return x * pt.y - y * pt.x;
  }
  inline bool operator<(const point &p) const {
    return make_pair(x, y) < make_pair(p.x, p.y);
  }
};
int n;
point ps[1005];
vector<int> get_hull() {
  vector<int> res;
  for (int i = 0; i < (n); ++i) {
    while (((int)(res).size()) > 1 &&
           (ps[i] - ps[res[((int)(res).size()) - 2]]) *
                   (ps[res.back()] - ps[res[((int)(res).size()) - 2]]) >=
               0) {
      res.pop_back();
    }
    res.push_back(i);
  }
  res.pop_back();
  vector<int> res2 = res;
  res.clear();
  for (int i = (n - 1); ((-1) > 0 ? i <= (0) : i >= (0)); i += (-1)) {
    while (((int)(res).size()) > 1 &&
           (ps[i] - ps[res[((int)(res).size()) - 2]]) *
                   (ps[res.back()] - ps[res[((int)(res).size()) - 2]]) >=
               0) {
      res.pop_back();
    }
    res.push_back(i);
  }
  res.pop_back();
  res2.insert(res2.end(), (res).begin(), (res).end());
  return res2;
}
bool inTriangle(int x, int a, int b, int c) {
  int jab = (ps[a] - ps[x]) * (ps[b] - ps[x]) > 0;
  int jbc = (ps[b] - ps[x]) * (ps[c] - ps[x]) > 0;
  int jca = (ps[c] - ps[x]) * (ps[a] - ps[x]) > 0;
  return jab == jbc && jbc == jca;
}
vector<pair<int, int> > egs;
void TriangleConnect(int a, int b, int c, vector<int> &pt) {
  int d = -1, ls = ps[a].c ^ ps[b].c ^ ps[c].c;
  for (int i = 0; i < (((int)(pt).size())); ++i) {
    if (ps[pt[i]].c == ls) {
      d = pt[i];
      break;
    }
  }
  if (!~d) {
    int co = ps[a].c == ls ? b : a;
    for (int i = 0; i < (((int)(pt).size())); ++i)
      egs.push_back(make_pair(co, pt[i]));
    return;
  }
  egs.push_back(make_pair(d, ps[a].c != ls ? (ps[b].c != ls ? c : b) : a));
  vector<int> pab, pbc, pca;
  for (int i = 0; i < (((int)(pt).size())); ++i) {
    if (pt[i] == d) continue;
    if (inTriangle(pt[i], a, b, d))
      pab.push_back(pt[i]);
    else if (inTriangle(pt[i], b, c, d))
      pbc.push_back(pt[i]);
    else
      pca.push_back(pt[i]);
  }
  TriangleConnect(a, b, d, pab);
  TriangleConnect(b, c, d, pbc);
  TriangleConnect(c, a, d, pca);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    scanf("%lld%lld%d", &ps[i].x, &ps[i].y, &ps[i].c);
    ps[i].id = i;
  }
  if (n == 1) return puts("0"), 0;
  sort(ps, ps + n);
  vector<int> h = get_hull();
  int se = 0;
  for (int i = 0; i < (((int)(h).size())); ++i)
    if (ps[h[i]].c != ps[h[(i + 1) % ((int)(h).size())]].c) ++se;
  if (se > 2) return puts("Impossible"), 0;
  if (!se) {
    int d = -1;
    for (int i = 0; i < (n); ++i)
      if (ps[i].c != ps[h[0]].c) {
        d = i;
        break;
      }
    if (!~d) {
      printf("%d\n", n - 1);
      for (int i = 1; i <= (n - 1); ++i) printf("%d %d\n", 0, i);
      return 0;
    }
    for (int i = 0; i < (((int)(h).size()) - 1); ++i)
      egs.push_back(make_pair(h[i], h[i + 1]));
    for (int i = 0; i < (((int)(h).size())); ++i) {
      int a = h[i], b = h[(i + 1) % ((int)(h).size())];
      vector<int> pts;
      for (int j = 0; j < (n); ++j)
        if (inTriangle(j, a, b, d)) pts.push_back(j);
      TriangleConnect(h[i], h[(i + 1) % ((int)(h).size())], d, pts);
    }
  } else {
    int f0 = -1, f1 = -1;
    for (int i = 0; i < (((int)(h).size())); ++i)
      if (ps[h[i]].c != ps[h[(i + 1) % ((int)(h).size())]].c) {
        if (ps[h[i]].c)
          f1 = i;
        else
          f0 = i;
      }
    for (int i = 0; i < (((int)(h).size())); ++i) {
      int a = h[i], b = h[(i + 1) % ((int)(h).size())], c;
      if (ps[a].c != ps[b].c) continue;
      egs.push_back(make_pair(a, b));
      if (ps[a].c)
        c = h[f0];
      else
        c = h[f1];
      vector<int> pts;
      for (int j = 0; j < (n); ++j)
        if (inTriangle(j, a, b, c)) pts.push_back(j);
      TriangleConnect(h[i], h[(i + 1) % ((int)(h).size())], c, pts);
    }
  }
  printf("%d\n", ((int)(egs).size()));
  for (int i = 0; i < (((int)(egs).size())); ++i)
    printf("%d %d\n", ps[egs[i].first].id, ps[egs[i].second].id);
  return 0;
}
