#include <bits/stdc++.h>
const int N = 10005, M = 1000000;
std::pair<int, int> operator-(std::pair<int, int> a, std::pair<int, int> b) {
  return std::pair<int, int>(a.first - b.first, a.second - b.second);
}
long long operator*(std::pair<int, int> a, std::pair<int, int> b) {
  return (long long)a.first * b.second - (long long)a.second * b.first;
}
int n, lu;
std::mt19937 rnd(std::time(0) + (size_t) new char);
std::pair<int, int> p[N];
int col[N];
long long area(int a, int b, int c) {
  return std::abs((p[b] - p[a]) * (p[c] - p[a]));
}
bool in_triangle(int first, int a, int b, int c) {
  return area(first, a, b) + area(first, a, c) + area(first, b, c) ==
         area(a, b, c);
}
void split(const std::vector<int> &first, int a, int b, int c,
           std::vector<int> &ret) {
  ret.clear();
  for (int t : first)
    if (in_triangle(t, a, b, c)) ret.emplace_back(t);
}
std::set<std::pair<int, int>> s;
void link(int first, int second) {
  if (first > second) std::swap(first, second);
  s.emplace(first, second);
}
void solve(int a, int b, int c, const std::vector<int> &first, int color) {
  std::vector<int> A, B, C, tmp;
  int cnt = 0, id = -1;
  for (int t : first)
    if (col[t] != color) ++cnt;
  if (!cnt) {
    link(a, b);
    for (int t : first) link(a, t);
    return;
  }
  if (cnt == first.size()) {
    link(a, b);
    for (int t : first) link(c, t);
    return;
  }
  int base = rnd() % cnt;
  for (int t : first)
    if (color != col[t] && !base--)
      id = t;
    else
      tmp.emplace_back(t);
  split(tmp, a, b, id, A), solve(a, b, id, A, color);
  split(tmp, b, c, id, B), solve(id, c, b, B, !color);
  split(tmp, c, a, id, C), solve(id, c, a, C, !color);
}
int rk[N], stack[N], top;
bool cmp(int first, int second) {
  return (p[first] - p[rk[0]]) * (p[second] - p[rk[0]]) > 0;
}
std::vector<int> convex_hull() {
  for (int i = 0; i < n; ++i) rk[i] = i;
  std::swap(rk[0], rk[std::min_element(p, p + n) - p]);
  std::sort(rk + 1, rk + n, cmp);
  for (int i = 0; i < n; ++i) {
    while (top > 1 && (p[rk[i]] - p[stack[top - 1]]) *
                              (p[stack[top - 1]] - p[stack[top - 2]]) >
                          0)
      --top;
    stack[top++] = rk[i];
  }
  return std::vector<int>(stack, stack + top);
}
bool onside[N];
std::vector<int> nodes;
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n;
  for (int i = 0; i < n; ++i) std::cin >> p[i].first >> p[i].second >> col[i];
  std::vector<int> h = convex_hull(), all;
  for (int i = 0; i < h.size(); ++i) onside[h[i]] = 1;
  for (int i = 0; i < n; ++i)
    if (!onside[i]) all.emplace_back(i);
  int c = col[h[0]], last_black = -1;
  std::vector<int> white;
  white.emplace_back(h[0]);
  for (int i = 1; i < h.size(); ++i) {
    if (col[h[i]] == c) {
      if (col[h[i - 1]] != c)
        split(all, h[0], h[i], h[i - 1], nodes),
            solve(h[0], h[i], h[i - 1], nodes, c);
      ;
      white.emplace_back(h[i]);
    } else {
      last_black = h[i];
      for (int j = 0; j + 1 < white.size(); ++j)
        split(all, white[j], white[j + 1], h[i], nodes),
            solve(white[j], white[j + 1], h[i], nodes, c);
      ;
      white.clear(), white.emplace_back(h[0]);
      if (col[h[i - 1]] != c)
        split(all, h[i - 1], h[i], h[0], nodes),
            solve(h[i - 1], h[i], h[0], nodes, !c);
      ;
    }
  }
  if (last_black == -1) {
    for (int i = 0; i + 1 < h.size(); ++i) link(h[i], h[i + 1]);
    int center = -1;
    for (int e : all)
      if (col[e] != c) {
        center = e;
        break;
      }
    if (center == -1) {
      for (int e : all) link(h[0], e);
    } else {
      for (int i = 0; i + 1 < h.size(); ++i)
        split(all, h[i], h[i + 1], center, nodes),
            solve(h[i], h[i + 1], center, nodes, c);
      ;
    }
  } else {
    for (int i = 0; i + 1 < white.size(); ++i)
      split(all, white[i], white[i + 1], last_black, nodes),
          solve(white[i], white[i + 1], last_black, nodes, c);
    ;
  }
  if (s.size() < n - 2)
    std::cout << "Impossible\n";
  else {
    std::cout << s.size() << '\n';
    for (auto e : s) std::cout << e.first << ' ' << e.second << '\n';
  }
  return 0;
}
