#include <iostream>
#include <bits/stdc++.h>

using namespace std;

vector< vector < int > > adj;
typedef long long ll;
struct node{
    ll x, y;
    int label;
    int index;
};



typedef struct node vertex;


bool compareY(vertex i1, vertex i2)
{
    return (i1.y > i2.y);
}
vertex minY, minY1;
bool compareAngle(vertex i1, vertex i2)
{
    return (atan2(i1.y, i1.x) > atan2(i2.y, i2.x));
}

int pa[3000];
int sz[3000];
int get(int i)
{
    if(pa[i] != i)
        return get(pa[i]);
    else
        return i;
}
void add(int i , int j)
{
    if(get(i) != get(j))
    {
        if(sz[get(i)] > sz[get(j)])
        {
            pa[get(i)] = get(j);
            sz[get(j)] += sz[get(i)];
        }
        else
        {
            pa[get(j)] = get(i);
            sz[get(i)] += sz[get(j)];
        }
    }
}


int main()
{
    int n;
    ios_base::sync_with_stdio(false);
    vertex v[2000];
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin  >> v[i].x >> v[i].y >> v[i].label;
        v[i].index = i + 1;
    }
    sort(v , v + n, compareY);
    while(v[n - 1].label == v[n - 1].index && n > 0)
    {
        n--;
    }
    if(n == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < n; i++)
    {
        v[i].x -= v[n - 1].x;
        v[i].y -= v[n - 1].y;
    }
    sort(v, v + n - 1, compareAngle);

    for(int i = 0; i < n; i++)
    {
        //cout << v[i].index << endl;
        pa[v[i].index] = v[i].index;
        sz[v[i].index] = 1;
    }
    for(int i = 0; i < n; i ++)
    {
        add(v[i].label , v[i].index);
    }
    vector < pair < int , int > > que;
    for(int i = 0; i < n - 2; i++)
    {
        if(get(v[i].index) != get(v[i + 1].index))
        {
            que.push_back({v[i].index , v[i + 1].index});
            //cout << v[i].index << " " << v[i + 1].index << endl;
            swap(v[i].label, v[i + 1].label);
            add(v[i].label, v[i + 1].label);
        }
    }
    int b[2200];
    for(int i = 0; i < n; i ++)
    {
        b[v[i].index] = i;
    }
    int label = v[n - 1].index;
    int i = n - 1;

    while(true)
    {
        if(label != v[i].label)
            que.push_back({label, v[i].label});
        i = b[v[i].label];
        if(i == n - 1)
            break;
    }
    cout << que.size() << endl;;
    for(int i = 0; i < que.size(); i++)
    {
        cout << que[i].first << " " << que[i].second << endl;
    }
    return 0;

}
