#include <bits/stdc++.h>
using namespace std;
const int N = 1010, inf = 0x3f3f3f3f;
struct point {
  int x, y, col;
  long long operator*(const point &rhs) const { return y * rhs.x - x * rhs.y; }
  point operator-(const point &rhs) const { return {x - rhs.x, y - rhs.y}; }
  bool operator<(const point &rhs) const {
    return x != rhs.x ? x < rhs.x : y < rhs.y;
  }
  void print(void) {
    cerr << "point = {" << x << ", " << y << "}, have color = " << col << endl;
  }
} p[N];
vector<int> cur;
int top, st[N], n;
bool ban[N], was[N];
bool cmp(int x, int y) { return (p[x] - p[cur[0]]) * (p[y] - p[cur[0]]) < 0; }
void build(void) {
  cur.clear();
  for (int i = 0; i < n; i++) {
    if (!ban[i]) {
      cur.push_back(i);
    }
  }
  int id = 0;
  for (int i = 1; i < cur.size(); i++) {
    if (p[cur[i]] < p[cur[id]]) {
      id = i;
    }
  }
  swap(cur[0], cur[id]);
  sort(cur.begin() + 1, cur.begin() + cur.size(), cmp);
  st[0] = cur[0];
  st[1] = cur[1];
  top = 2;
  for (int i = 2; i < cur.size(); i++) {
    while (top > 1 &&
           (p[st[top - 1]] - p[st[top - 2]]) * (p[cur[i]] - p[st[top - 2]]) >
               0) {
      top--;
    }
    st[top++] = cur[i];
  }
}
int main(void) {
  scanf("%d", &n);
  int stat = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].col);
    stat |= 1 << p[i].col;
  }
  if (stat < 3) {
    cout << n - 1 << endl;
    for (int i = 1; i < n; i++) {
      cout << 0 << " " << i << endl;
    }
    return 0;
  }
  build();
  int cnt = 0;
  for (int i = 0; i < top; i++) {
    cnt += p[st[i]].col != p[st[(i + 1) % top]].col;
    was[st[i]] = true;
  }
  if (cnt > 2) {
    puts("Impossible");
    return 0;
  }
  vector<pair<int, int> > ans;
  while (ans.size() < n - 2) {
    int pos = 0, r, l;
    for (; pos < top; pos++) {
      r = (pos + 1) % top;
      l = (pos - 1 + top) % top;
      if ((p[st[r]].col != p[st[pos]].col) ^ (p[st[l]].col != p[st[pos]].col)) {
        break;
      }
    }
    if (pos == top) {
      pos = top - 1;
    }
    int x = st[pos];
    if (p[st[r]].col == p[x].col) {
      ans.emplace_back(st[r], x);
    } else {
      ans.emplace_back(st[l], x);
    }
    ban[x] = true;
    bool found = true;
    while (found) {
      found = false;
      build();
      for (int i = 0; i < top; i++) {
        if (!was[st[i]] && p[st[i]].col == p[x].col) {
          ans.emplace_back(x, st[i]);
          found = true;
          ban[st[i]] = true;
        }
      }
    }
    for (int i = 0; i < top; i++) {
      was[st[i]] = true;
    }
  }
  cout << n - 2 << endl;
  for (pair<int, int> u : ans) {
    cout << u.first << " " << u.second << endl;
  }
  return 0;
}
