#include <vector>
#include <iostream>
using namespace std;

struct edge{
	int from;
	int to;
	int cap;
};

int n,m;
vector<edge> list;
vector<vector<edge*> > adj;
int a,b,c;
edge t;
int main(){
	cin>>n>>m;
	int g=0;
	adj.resize(n+3);
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;
		
		t.from=a;
		t.to=b;
		t.cap=c;
		list.push_back(t);
		g++;
		adj[a].push_back(&list[g-1]);
		adj[b].push_back(&list[g-1]);
	}
	for(int i=1;i<=n;i++){
		cout<<"adjacent nodes of the node "<<i<<" are :"<<endl;
		for(int j=0;j<adj[i].size();j++){
			if(adj[i][j]->from==i){
				cout<<adj[i][j]->to<<" ";
			} else {
				cout<<adj[i][j]->from<<" ";
			}
		}
		cout<<endl<<endl;
	}
}