#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
//#define file
using namespace std;

struct type{int x,y,id; double s;} a[2001];
int n,i,j,k,l,Tot;
int X[2001],Y[2001],A[2001];
int num[2001];
bool bz[2001];
int mn,mn2;
int ans[4000001][2],tot;
int fa[2001];

bool cmp(type a,type b) {return a.s<b.s;}
void add(int x,int y)
{
	++tot;
	ans[tot][0]=x,ans[tot][1]=y;
}
int gf(int t) {if (fa[t]==t) return t; fa[t]=gf(fa[t]);return fa[t];}
void link(int x,int y) {if (gf(x)!=gf(y)) fa[fa[x]]=fa[y];}

int main()
{
	#ifdef file
	freopen("CF1508D.in","r",stdin);
	#endif
	
	scanf("%d",&n);
	fo(i,1,n) scanf("%d%d%d",&X[i],&Y[i],&A[i]),fa[i]=i;
	
	l=0;
	fo(i,1,n)
	if (A[i]!=i && !bz[i])
	{
		++l;j=i;
		while (!bz[j])
		{
			bz[j]=1,num[j]=l;
			a[++Tot]={X[j],Y[j],j};
			j=A[j];
		}
	}
	if (!Tot) {printf("0\n");return 0;}
	
	mn=1000000000,mn2=-1;
	fo(i,1,Tot) if (a[i].y<mn) mn=a[i].y,mn2=i;
	fo(i,1,Tot) if (i!=mn2) a[i]=type{a[i].x-a[mn2].x,a[i].y-a[mn2].y,a[i].id};
	swap(a[mn2],a[Tot]),--Tot;
	fo(i,1,Tot) a[i].s=atan2(a[i].y,a[i].x);
	sort(a+1,a+Tot+1,cmp);
	fo(i,2,Tot)
	if (gf(num[a[i].id])!=gf(num[a[i-1].id]))
	link(num[a[i].id],num[a[i-1].id]),swap(A[a[i].id],A[a[i-1].id]),add(a[i].id,a[i-1].id);
	
	mn2=a[Tot+1].id,i=mn2;
	while (A[i]!=mn2) add(mn2,A[i]),i=A[i];
	
	printf("%d\n",tot);
	fo(i,1,tot) printf("%d %d\n",ans[i][0],ans[i][1]);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}