#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
using ll = long long;
using ld = long double;
ll MOD = 1000000007;
const ll root = 3;
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 2001;
int n;
vector<ttgl> res;
int ord[mxN];
int lab[mxN];
int dsu[mxN];
int bck[mxN];
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];
int half(pt x) { return x.y == 0 ? x.x < 0 : x.y > 0; } 
ll cross(pt a, pt b) {
    return a.x * b.y - a.y * b.x;
}
bool angsort(pt a, pt b) {
	int A = half(a), B = half(b);
	return A == B ? cross(a,b) > 0 : A < B; 
}
int find(int a) {
    return a==dsu[a] ? a : dsu[a] = find(dsu[a]);
}
bool merge(int a, int b) {
    a = find(a);
    b = find(b);
    if(a==b)return 0;
    dsu[b] = a;
    return 1;
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    iota(dsu, dsu+mxN, 0);
    owo(i, 0, n) {
        cin>>arr[i].x>>arr[i].y>>lab[i];
        lab[i]--;
        merge(i, lab[i]);
    }
    iota(ord, ord+n, 0);
    sort(ord, ord+n, [&](int a, int b) {
        return arr[a] < arr[b];
    });
    int rt = 0;
    owo(_, 0, n) {
        int i = ord[_];
        if(lab[i]==i)continue;
        rt = i;
        vector<int> nord;
        owo(j, 0, n) {
            if(i!=j)nord.senpai(j);
        }
        sort(nord.begin(), nord.end(), [&](int a, int b) {
            return angsort(arr[a] - arr[i], arr[b] - arr[i]);
        });
        owo(j, 1, n-1) {
            if(merge(nord[j], nord[j-1])) {
                res.senpai({nord[j], nord[j-1]});
                swap(lab[nord[j]], lab[nord[j-1]]);
            }
        }
        int curr = lab[i];
        while(curr!=i) {
            res.senpai({i, curr});
            curr = lab[curr];
        }
        break;
    }
    /*if(res.size() > 0 && res[0].first==394) {
        cout<<rt<<"\n";
        int a = res[384].first;
        int b = res[384].second;
        cout<<a<<" "<<b<<" "<<arr[a].x<<" "<<arr[a].y<<" "<<arr[b].x<<" "<<arr[b].y<<"\n";
        a = res[463].first;
        b = res[463].second;
        cout<<a<<" "<<b<<" "<<arr[a].x<<" "<<arr[a].y<<" "<<arr[b].x<<" "<<arr[b].y<<"\n";
    }*/
    cout<<res.size()<<"\n";
    for(auto p: res) {
        cout<<p.first+1<<" "<<p.second+1<<"\n";
    }
    return 0;
}