#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
# define inf 0x3f3f3f3f
# define maxn 100005
using namespace std;
int u[10],v[10],w[10];
struct node
{
int head;
int next;
} q[100];
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=1; i<=n; i++)
{
q[i].head=-1;
}
for(int i=1; i<=m; i++)
{
cin>>u[i]>>v[i]>>w[i];
q[i].next=q[u[i]].head;
q[u[i]].head=i;
}
for(int i=1; i<=n; i++)
{
int t=q[i].head;
while(t!=-1)
{
cout<<u[t]<<" "<<v[t]<<" "<<w[t]<<endl;
t=q[t].next;
}
}
return 0;
}
}