#include <iostream>
using namespace std;
int first[2505] , next[6505] , top = 0 , worth[6505] , to[6505];
void add()
{
int u , v , w ;
cin >> u >> v >> w;
next[++top] = first[u];
first[u] = top;
to[top] = v;
worth[top] = w;
return ;
}
int main ()
{
int n , m;
cin >> n >> m;
for(int i = 1 ; i <= m ; i++)
{
add();
}
for(int i = 1 ; i <= n ; i++)
{
cout << i << ": ";
for(int e = first[i] ; e ; e = next[e])
{
cout << to[e]<< " ";
}
cout << endl;
}
return 0;
}