#include <bits/stdc++.h>
using namespace std;
const int N = 1100;

struct PT{
	int x, y, c;
} p[N];

int vect(PT p, PT p1, PT p2) {
	return (p1.x - p.x) * (p2.y - p.y) - (p2.x - p.x) * (p1.y - p.y);
}

vector<int> convex_Hull(vector<int> ps) {
	if (ps.size() <= 1) return ps;
	int n = ps.size(), k = 0;
	vector<int> ch(2 * n);
	for (int i = 0; i < n; ch[k++] = ps[i++]) {
		while (k >= 2 && vect(p[ch[k-2]], p[ch[k-1]], p[ps[i]]) <= 0) --k;
	}
	for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) {
		while (k >= t && vect(p[ch[k-2]], p[ch[k-1]], p[ps[i]]) <= 0) --k;
	}
	ch.resize(k - 1);
	return ch;
}

bool select[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y >> p[i].c;
	sort(p, p + n, [](PT a, PT b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); });
	vector<int> ans;
	for (int i = 0; i < n; i++) {
		select[i] = 1;
	}
	int flg = 0;
	while (1) {
		vector<int> tmp;
		for (int i = 0; i < n; i++) {
			if (select[i]) tmp.push_back(i);
		}
		vector<int> convex = convex_Hull(tmp);
		int m = convex.size();
		convex.push_back(convex[0]);
		int changes = 0;
		vector<int> CHS;
		int cnt[2] = {0};
		for (int i = 0; i < m; i++) {
			cnt[p[convex[i]].c]++;
			if (p[convex[i]].c != p[convex[i+1]].c) {
				changes++;
			}
		}
		if (cnt[0] <= 1 && cnt[1] <= 1) break;
		if (changes > 2) {
			flg = 1;
			break;
		}
		if (!changes) {
			ans.push_back(convex[0]);
			ans.push_back(convex[1]);
			select[convex[0]] = 0;
			continue;
		} else {
			int which = 0;
			if (cnt[0] <= 1) which = 1;
			for (int i = 0; i < m; i++) {
				if (p[convex[i]].c != p[convex[i+1]].c && p[convex[i+1]].c == which) {
					int j = (i+2) % m;
					assert(p[convex[j]].c == which);
					select[convex[i+1]] = 0;
					ans.push_back(convex[i+1]);
					ans.push_back(convex[j]);
				}
			}
		}
	}
	if (flg) return puts("Impossible"), 0;
	cout << ans.size() / 2 << endl;
	for (int i = 0; i < ans.size(); i+=2) {
		cout << ans[i] << ' ' << ans[i+1] << endl;
	}
	return 0;
}

