#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
struct Point {
  long long x, y;
  int col, id;
  Point() {}
  Point(long long x, long long y) : x(x), y(y) {}
  long double abs() const { return hypot(x, y); }
  long double arg() const { return atan2(y, x); }
  Point operator*(double o) const { return Point(x * o, y * o); }
  Point operator+(const Point& o) const { return Point(x + o.x, y + o.y); }
  Point operator-(const Point& o) const { return Point(x - o.x, y - o.y); }
  Point operator/(double o) const { return Point(x / o, y / o); }
  bool operator<(const Point& o) const {
    return x < o.x - 1e-9 || (x < o.x + 1e-9 && y < o.y - 1e-9);
  }
  friend bool operator==(const Point& r1, const Point& r2) {
    return r1.x == r2.x && r1.y == r2.y;
  }
  long long cross(Point b) const { return x * b.y - b.x * y; }
  void readin(int i) {
    id = i;
    scanf("%lld%lld%d", &x, &y, &col);
  }
};
Point p[1035];
vector<Point> convex(vector<Point>& vp) {
  sort(vp.begin(), vp.end());
  int N = unique(vp.begin(), vp.end()) - vp.begin();
  vector<Point> ans1, ans2;
  for (int(i) = 0; (i) < (int)(N); (i)++) {
    while (ans1.size() > 1) {
      Point o = ans1[ans1.size() - 2], a = ans1.back();
      if ((a - o).cross(vp[i] - o) <= 0) {
        ans1.pop_back();
      } else
        break;
    }
    ans1.push_back(vp[i]);
  }
  for (int i = N - 1; i >= 0; i--) {
    while (ans2.size() > 1) {
      Point o = ans2[ans2.size() - 2], a = ans2.back();
      if ((a - o).cross(vp[i] - o) <= 0) {
        ans2.pop_back();
      } else
        break;
    }
    ans2.push_back(vp[i]);
  }
  for (int i = 1; i < ans2.size() - 1; i++) ans1.push_back(ans2[i]);
  return ans1;
}
vector<pair<int, int> > ans;
bool vis[1035];
set<int> sp[2];
void ppt() {
  printf("%d\n", (int)ans.size());
  for (auto p : ans) printf("%d %d\n", p.first, p.second);
  exit(0);
}
long long calArea(int a, int b, int c) {
  return abs((p[a] - p[b]).cross(p[c] - p[b]));
}
bool isInTir(int a, int b, int c, int D) {
  long long s = calArea(a, b, c);
  s -= calArea(a, b, D) + calArea(b, c, D) + calArea(a, c, D);
  return s == 0;
}
void cal(int x1, int x2, int y) {
  int C = p[y].col;
  for (int tid : sp[C]) {
    if (isInTir(x1, x2, y, tid)) {
      sp[C].erase(tid);
      ans.push_back({tid, y});
      cal(x1, x2, tid);
      cal(tid, y, x1);
      cal(tid, y, x2);
      return;
    }
  }
  vector<int> tmp;
  for (int tid : sp[C ^ 1]) {
    if (isInTir(x1, x2, y, tid)) {
      tmp.push_back(tid);
      ans.push_back({x1, tid});
    }
  }
  for (int tid : tmp) sp[C ^ 1].erase(tid);
}
void fmain(int tid) {
  scanf("%d", &n);
  for (int(i) = 0; (i) < (int)(n); (i)++) p[i].readin(i);
  if (n == 1) {
    puts("0");
    return;
  } else if (n == 2) {
    if (p[0].col == p[1].col) {
      puts("1\n0 1");
    } else {
      puts("0");
    }
    return;
  }
  for (int(i) = 0; (i) < (int)(n); (i)++) sp[p[i].col].insert(i);
  vector<Point> tmp;
  for (int(i) = 0; (i) < (int)(n); (i)++) tmp.push_back(p[i]);
  vector<Point> con = convex(tmp);
  int N = con.size();
  reverse(con.begin(), con.end());
  vector<int> cs;
  for (int(i) = 0; (i) < (int)(N); (i)++) {
    if (con[i].col != con[(i + 1) % N].col) {
      cs.push_back(i);
    }
  }
  if (cs.size() > 2) {
    puts("Impossible");
    return;
  }
  if (cs.empty()) {
    for (int(i) = 0; (i) < (int)(N - 1); (i)++) {
      ans.push_back({con[i].id, con[i + 1].id});
    }
    for (int(i) = 0; (i) < (int)(N); (i)++) {
      vis[con[i].id] = 1;
      sp[con[i].col].erase(con[i].id);
    }
    bool fg = 0;
    for (int(i) = 0; (i) < (int)(n); (i)++)
      if (!vis[i] && p[i].col != con[0].col) {
        sp[p[i].col].erase(p[i].id);
        for (int(j) = 0; (j) < (int)(N); (j)++)
          cal(con[j].id, con[(j + 1) % N].id, i);
        fg = 1;
        break;
      }
    if (!fg) {
      for (int id : sp[con[0].col]) ans.push_back({con[0].id, id});
    }
  } else {
    int I = cs[0], J = cs[1];
    if (J < I) swap(I, J);
    for (int i = I + 1; i < J; i++) {
      ans.push_back({con[i].id, con[i + 1].id});
      sp[con[J].col].erase(con[i].id);
    }
    sp[con[J].col].erase(con[J].id);
    for (int i = J + 1; i < I + N; i++) {
      ans.push_back({con[i % N].id, con[(i + 1) % N].id});
      sp[con[I].col].erase(con[i % N].id);
    }
    sp[con[I].col].erase(con[I].id);
    for (int i = I + 1; i < J; i++) {
      cal(con[i].id, con[i + 1].id, con[I].id);
    }
    for (int i = J + 1; i < I + N; i++) {
      cal(con[i % N].id, con[(i + 1) % N].id, con[J].id);
    }
  }
  ppt();
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
