/*#include <stdio.h>
int a[1001];
int n, i, j, k=0, temp;
int main()
{
scanf("%d", &n);
for (i=1; i<=n; i++)
scanf("%d", &a[i]);
for(i=1; i<n; i++)
{
k=0;
for(j=1; j<=n-i; j++)
{
if (a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
k++;
}
}
if(k==0) break;
}
printf("%d", i-1);
return 0;
}
*/
/*
#include <stdio.h>
int a[10001];
int n, i, j, temp;
int main() {
for (i=1; i<=7; i++)
scanf("%d", &a[i]);
for(i=1; i<7; i++)
{
for(j=1;j<=7-i;j++)
{
if (a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
printf("%d\n%d", a[7],a[6]);
return 0;
}
*/
/*
#include <stdio.h>
typedef struct
{
char name[50];
int num;
}student;
student a[51], temp;
int n, i, j;
char k;
int main() {
scanf("%d", &n);
for (i=1; i<=n; i++)
scanf("%s %d", a[i].name,&a[i].num);
for(i=1; i<n; i++)
{
for(j=1;j<=n-i;j++)
{
if (a[j].num < a[j+1].num)
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
printf("%s", a[3].name);
return 0;
}
*/
#include<stdio.h>
typedef struct
{
int num1, num2, num3;
}student;
student a[1001],temp;
int n,i,j;
int main()
{
scanf("%d", &n);
for(i=1;i<=n;i++)
{
scanf("%d %d", &a[i].num1,&a[i].num2);
a[i].num3=i;
}
for(i=1; i<n; i++)
{
for(j=1;j<=n-i;j++)
{
if (a[j].num1 < a[j+1].num1)
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
if(a[j].num1 == a[j+1].num1)
{
if(a[j].num2<a[j+1].num2)
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
if(a[j].num2==a[j+1].num2)
{
if(a[j].num3>a[j+1].num3)
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
}
for (i=1;i<=n;i++)
printf("%d %d %d\n", a[i].num3,a[i].num1,a[i].num2);
return 0;
}