#include<iostream>
#include<algorithm>
using namespace std;
const int N=100010;
int n;
struct Row
{
string id,name;
int grade;
}rows[N];
bool cmp1(Row a,Row b)
{
return a.id<b.id;
}
bool cmp2(Row a,Row b)
{
if(a.name!=b.name) return a.name<b.name;
return a.id<b.id;
}
bool cmp3(Row a,Row b)
{
if(a.grade!=b.grade) return a.grade<b.grade;
return a.id<b.id;
}
int main()
{
int c;
scanf("%d%d",&n,&c);
char id[10],name[10];
for(int i=0;i<n;i++)
{
int grade;
scanf("%s%s%d",id,name,&grade);
rows[i]={id,name,grade};
}
if(c==1) sort(rows,rows+n,cmp1);
else if(c==2) sort(rows,rows+n,cmp2);
else sort(rows,rows+n,cmp3);
for(int i=0;i<n;i++)
printf("%s %s %d\n",rows[i].id.c_str(),rows[i].name.c_str(),rows[i].grade);
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100010;
int n,m;
struct Student
{
string id,name;
int grade;
}S[N];
bool cmp1(Student a,Student b)
{
return a.id<b.id;
}
bool cmp2(Student a,Student b)
{
if(a.name!=b.name) return a.name<b.name;
else return a.id<b.id;
}
bool cmp3(Student a,Student b)
{
if(a.grade!=b.grade) return a.grade<b.grade;
else return a.id<b.id;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>S[i].id>>S[i].name>>S[i].grade;
if(m==1) sort(S,S+n,cmp1);
else if(m==2) sort(S,S+n,cmp2);
else sort(S,S+n,cmp3);
for(int i=0;i<n;i++)
cout<<S[i].id<<' '<<S[i].name<<' '<<S[i].grade<<endl;
return 0;
}