#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  Point() {}
  Point(int _x, int _y) {
    x = _x;
    y = _y;
  }
} points[1005];
struct lineSegment {
  Point A, B;
  lineSegment() {}
  lineSegment(Point _A, Point _B) {
    A = _A;
    B = _B;
  }
  lineSegment(int ax, int ay, int bx, int by) {
    A = Point(ax, ay);
    B = Point(bx, by);
  }
} segment[1003];
Point operator+(const Point &u, const Point &v) {
  return Point(u.x + v.x, u.y + v.y);
}
Point operator-(const Point &u, const Point &v) {
  return Point(u.x - v.x, u.y - v.y);
}
long long int crsp(Point u, Point v) {
  return (long long int)u.x * v.y - (long long int)u.y * v.x;
}
int turn(Point st, Point mid, Point ed) {
  long long int v = crsp(mid - st, ed - st);
  if (!v) return 0;
  return v > 0 ? 1 : -1;
}
bool lineIntersection(lineSegment p, lineSegment q) {
  if (turn(p.A, p.B, q.A) == -turn(p.A, p.B, q.B) &&
      turn(q.A, q.B, p.A) == -turn(q.A, q.B, p.B))
    return 1;
  return 0;
}
bool isPointOnSegment(Point p, lineSegment line) {
  if (!(turn(line.A, line.B, p))) {
    Point r = line.A;
    Point s = line.B;
    if ((long long int)(p.x - r.x) * (p.x - s.x) <= 0 &&
        (long long int)(p.y - r.y) * (p.y - s.y) <= 0)
      return 1;
  }
  return 0;
}
int RayShoot(vector<lineSegment> &v, Point A, Point B) {
  int cnt = 0;
  lineSegment Q = lineSegment(A, B);
  for (int i = 0; i < v.size(); i++) {
    lineSegment &P = v[i];
    if (isPointOnSegment(A, P)) return 1;
    cnt += lineIntersection(P, Q);
  }
  return cnt;
}
vector<int> adj1[1003];
vector<int> adj2[1003];
void dfs1(int s, int par = -1) {
  for (auto x : adj1[s]) {
    if (x == par) continue;
    cout << s << " " << x << endl;
    dfs1(x, s);
  }
}
void dfs2(int s, int par = -1) {
  for (auto x : adj2[s]) {
    if (x == par) continue;
    cout << s << " " << x << endl;
    dfs2(x, s);
  }
}
int main() {
  int n, l = 0;
  cin >> n;
  int c[n], node1, node2;
  for (int i = 0; i < n; i++) cin >> points[i].x >> points[i].y >> c[i];
  vector<pair<int, int> > ans;
  vector<lineSegment> v;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (c[i] == c[j]) {
        lineSegment p;
        if (l == 0)
          v.push_back(lineSegment(points[i], points[j]));
        else
          p = lineSegment(points[i], points[j]);
        if (v.size() > 0) {
          int s = 0;
          for (int k = 0; k < v.size(); k++) {
            if ((lineIntersection(v[k], p))) s = 1;
          }
          if (!s) {
            if (c[i] == 0) {
              adj1[i].push_back(j);
              adj1[j].push_back(i);
              node1 = i;
            } else {
              adj2[i].push_back(j);
              adj2[j].push_back(i);
              node2 = i;
            }
            ans.emplace_back(i, j);
          }
        } else {
          ans.emplace_back(i, j);
          if (c[i] == 0) {
            adj1[i].push_back(j);
            adj1[j].push_back(i);
          } else {
            adj2[i].push_back(j);
            adj2[j].push_back(i);
          }
        }
        l++;
      }
    }
  }
  if (ans.size() == 0) {
    cout << "Impossible" << endl;
    return 0;
  }
  cout << ans.size() << endl;
  dfs1(node1);
  dfs2(node2);
}
