#include<iostream>
#include<bits/stdc++.h>
using namespace std;
struct gold
{
int job_id;
int dl;
int p;
};
bool cmp(gold a,gold b)
{
return a.p>b.p;
}
int main()
{
gold A[101];
//code
int t;
cin>>t;
int N;
cin>>N;
for(int i=0; i<N; i++)
{
cin>>A[i].job_id;
cin>>A[i].dl;
cin>>A[i].p;
}
for(int i=0; i<=N-1; i++)
{
sort(A,A+N,cmp);
}
for(int i=0; i<N; i++)
{
cout<<A[i].job_id<<" "<<A[i].dl<<" "<<A[i].p<<endl;
}
return 0;
}