//快速排序+结构体
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
char name[50];
float height;
float weight;
} person;
person st[50];
int compare (const void * x, const void * y)
{
person *xx = (person*)x;
person *yy = (person*)y;
if (xx->height > yy->height || (xx->height == yy->height && (xx->weight) > (yy->weight)))
return -1;
return 1;
}
int main()
{
int n, i ;
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
while(scanf("%d",&n) == 1)
{
if(n == 0)break;
for(i = 0; i < n; i++) scanf("%s%fm%fkg",&st[i].name, &st[i].height, &st[i].weight);
qsort (st, n, sizeof(person), compare);
for(i = 0; i < n-1; i++)
printf("%s %.2fm %.1fkg\n\n",st[i].name, st[i].height, st[i].weight);
printf("%s %.2fm %.1fkg\n", st[n-1].name, st[n-1].height, st[n-1].weight);
}
return 0;
}