/*#include<stdio.h>
int sum=0;
int a;
int SuperSum(int k, int n)
{
if(k==0)
return n;
for(int i=1; i<=n; i++)
{
a = SuperSum(k-1,i);
if(k==1)
{
sum += a;
}
}
return sum;
}
int main()
{
int n,k;
while( scanf("%d %d", &k, &n) != EOF )
printf("%d\n", SuperSum(k, n));
}*/
//#include<stdio.h>
//
//struct student
//{
// int a;
// int b;
//};
//
//int main()
//{
// int n,i,j,cnt=0;
// struct student st[200];
//
// scanf("%d",&n);
// for(i=0; i<n; i++)
// {
// scanf("%d",&st[i].a);
// }
// for(i=0; i<n; i++)
// {
// cnt=0;
// for(j=0; j<n; j++)
// {
// if(st[i].a<st[j].a)
// {
// cnt++;
//
// }
// }
// st[i].b=cnt+1;
// }
// for(i=0; i<n; i++)
// {
// printf("%d %d\n",st[i].a,st[i].b);
// }
//}
struct student
{
int a;
int b;
int c;
};
int main()
{
int n,i,j,x,y,z,cnt;
struct student st[100]= {0};
int catchTeam[1000] = {0};
int max= -1;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d %d %d",&st[i].a,&st[i].b,&st[i].c);
}
i=0;
for(;;) {
max = -1;
for(j=0; j<n; j++) {
if(st[j].c > max) {
max = st[j].c;
z = j;
}
}
catchTeam[st[z].a]++;
if(catchTeam[st[z].a] < 3){
printf("%d %d\n", st[z].a, st[z].b);
st[z].c = 0;
i++;
}
else if(catchTeam[st[z].a] == 3) {
st[z].c = 0;
}
if(i == 3) break;
}
}