#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int t;
struct node
{
int from;
int to;
int dis;
int next;
}e[1000];
int head[1000];
int add(int from,int to,int dis)
{
t++;
e[t].from=from;
e[t].next=head[from];
e[t].to=to;
e[t].dis=dis;
head[from]=t;
}
int main()
{
cin >> n >> m;
for (int i=1;i<=m;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
add(y,x,z);
}
for (int i=1;i<=n;i++)
if (head[i]!=0)
{
printf("%d:",i);
for (int j=head[i];j!=0;j=e[j].next)
printf("%d ",e[j].to);
printf("\n");
}
return 0;
}