#include<stdio.h>
int main()
{
	struct khk{
		int year;
		int month;
		int day;
		char phone[30];
		char name[30];
	};
	khk s[30];
	struct khk t;
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;++i)
 scanf("%s %d %d %d %s",s[i].name,&s[i].year,&s[i].month,&s[i].day,s[i].phone);

	for(i=0;i<n;++i)
	for(j=0;j<n-1-i;++j)
	{
		if(s[j].year==s[j+1].year&&s[j].month==s[j+1].month){
		if(s[j].day>s[j+1].day)
		{
			t=s[j];s[j]=s[j+1];s[j+1]=t;
		}
		}
		else if(s[j].year==s[j+1].year)
		{
			if(s[j].month>s[j+1].month)
		{
			t=s[j];s[j]=s[j+1];s[j+1]=t;
		}
		}
		else
		{
			if(s[j].year>s[j+1].year)
		{
			t=s[j];s[j]=s[j+1];s[j+1]=t;
		}	
		}
		
	}
	for(i=0;i<n;++i)
	printf("%s %d/%d/%d %s\n",s[i].name,s[i].year,s[i].month,s[i].day,s[i].phone);
}