///个人题解,A题
#include<bits/stdc++.h>
using namespace std;
struct node{
int a,b,c;
bool operator<(const node &x)const{
if(c!=x.c) return c>x.c;
else if(a!=x.a) return a<x.a;
else return b<x.b;
}
}x[2010];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>x[i].a>>x[i].b>>x[i].c;
}
sort(x+1,x+1+n);
for(int i=1;i<=m;i++){
cout<<x[i].a<<' '<<x[i].b<<' '<<x[i].c<<'\n';
}
}