#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const double PI = acos(-1);
const int INF = 0x3f3f3f3f;
const int NINF = 0x3f3f3f40;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0x3f3f3f3f3f3f3f40;
const int mxN = 2001;
int n;
vector<pair<int, int> > ans;
void upd(int a, int b) { ans.push_back({a, b}); }
struct pt {
  ll x, y;
  pt(ll x = 0, ll y = 0) : x(x), y(y) {}
  bool operator<(const pt &o) const { return (x == o.x ? y < o.y : x < o.x); }
  pt operator-(const pt &o) const { return pt(x - o.x, y - o.y); }
} arr[mxN];
ll cross(pt a, pt b) { return a.x * b.y - a.y * b.x; }
bool contains(pt a, pt b, pt c, pt check) {
  return cross(b - a, check - a) > 0 && cross(c - b, check - b) > 0 &&
         cross(a - c, check - c) > 0;
}
bool col[mxN];
int rk[mxN], stk[mxN], top;
bool cmp(int a, int b) {
  return cross(arr[a] - arr[rk[0]], arr[b] - arr[rk[0]]) > 0;
}
vector<int> chull() {
  for (int i = (0); i < (n); ++i) rk[i] = i;
  swap(rk[0], rk[min_element(arr, arr + n) - arr]);
  sort(rk + 1, rk + n, cmp);
  for (int i = (0); i < (n); ++i) {
    while (top > 1 && cross(arr[rk[i]] - arr[stk[top - 1]],
                            arr[stk[top - 1]] - arr[stk[top - 2]]) > 0)
      --top;
    stk[top++] = rk[i];
  }
  return vector<int>(stk, stk + top);
}
void solve(int a, int b, int c, vector<int> req) {
  for (int k : req) {
    if (col[k] == col[a]) {
      upd(a, k);
      vector<int> nxt1, nxt2, nxt3;
      for (int p : req) {
        if (p ^ k) {
          if (contains(arr[c], arr[a], arr[k], arr[p]))
            nxt1.push_back(p);
          else if (contains(arr[b], arr[a], arr[k], arr[p]))
            nxt2.push_back(p);
          else
            nxt3.push_back(p);
        }
      }
      solve(c, a, k, nxt1);
      solve(b, a, k, nxt2);
      solve(k, b, c, nxt3);
      return;
    }
  }
  for (int k : req) {
    upd(b, k);
  }
}
int main() {
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  int a, b, c;
  for (int i = (0); i < (n); ++i) {
    cin >> a >> b >> c;
    arr[i] = pt(a, b);
    col[i] = c;
  }
  vector<int> hull = chull();
  for (int i = (1); i < (hull.size()); ++i) {
    if (col[hull[i - 1]] != col[hull[i]]) {
      hull.insert(hull.end(), hull.begin(), hull.begin() + i);
      hull.erase(hull.begin(), hull.begin() + i);
      break;
    }
  }
  int difcol = 0;
  for (int i = (1); i < (hull.size()); ++i) {
    if (col[hull[i - 1]] != col[hull[i]]) difcol++;
  }
  if (difcol > 1) {
    cout << "Impossible\n";
    exit(0);
  }
  if (difcol == 0) {
    for (int i = (1); i < (hull.size()); ++i) {
      upd(hull[i - 1], hull[i]);
    }
    bool flag = false;
    for (int i = (0); i < (n); ++i) {
      if (col[i] != col[hull[0]]) {
        vector<int> req;
        for (int j = (0); j < (hull.size()); ++j) {
          for (int k = (0); k < (n); ++k) {
            if (k != i && k != hull[j] && k != hull[(j + 1) % hull.size()] &&
                contains(arr[i], arr[hull[j]], arr[hull[(j + 1) % hull.size()]],
                         arr[k]))
              req.push_back(k);
          }
          solve(i, hull[j], hull[(j + 1) % hull.size()], req);
          req.clear();
        }
        flag = true;
        break;
      }
    }
    if (!flag) {
      for (int i = (0); i < (n); ++i) {
        for (int k : hull) {
          if (k == i) goto nxt;
        }
        upd(i, hull[0]);
      nxt:;
      }
    }
  } else {
    if (n == 1000 && arr[0].x == 0) cout << "debug" << endl;
    int bp;
    for (int i = (1); i < (hull.size()); ++i) {
      if (col[hull[i - 1]] != col[hull[i]]) bp = i;
    }
    vector<int> req;
    for (int j = (1); j < (bp); ++j) {
      upd(hull[j - 1], hull[j]);
      for (int k = (0); k < (n); ++k) {
        if (k != hull[bp] && k != hull[j - 1] && k != hull[j] &&
            contains(arr[hull[bp]], arr[hull[j - 1]], arr[hull[j]], arr[k]))
          req.push_back(k);
      }
      solve(hull[bp], hull[j - 1], hull[j], req);
      req.clear();
    }
    for (int j = (bp + 1); j < (hull.size()); ++j) {
      upd(hull[j - 1], hull[j]);
      for (int k = (0); k < (n); ++k) {
        if (k != hull[0] && k != hull[j - 1] && k != hull[j] &&
            contains(arr[hull[0]], arr[hull[j - 1]], arr[hull[j]], arr[k]))
          req.push_back(k);
      }
      solve(hull[0], hull[j - 1], hull[j], req);
      req.clear();
    }
  }
  cout << ans.size() << "\n";
  for (auto p : ans) {
    cout << (p.first) << " " << (p.second) << "\n";
  }
  return 0;
}
