.................................................................................................................................................................................................................
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,m,K,top;
int fa[20003],u[100003],v[100003],c[100003];
int au[20003],av[20003],ac[20003];
bool mark[100003];
int num[2];
int find(int x){
if(fa[x]==x){
return x;
}else{
return fa[x]=find(fa[x]);
}
}
void solve(bool typ,int mx){
for(int i=1;i<=m;i++){
if(c[i]==typ&&num[typ]<mx){
int p=find(u[i]),q=find(v[i]);
if(p!=q){
fa[p]=q;
au[++top]=u[i],av[yop]=v[i],ac[top]=c[i];
mark[i]=1;
num[typ]++;
}
}
}
}
int main(){
cin>>n>>m>>K;
for(int i=1;i<=m;i++){
cin>>u[i]>>v[i]>>c[i];
}
for(int i=1;i<=n;i++){
fa[i]=i;
}
num[0]=num[1]=0;
solve(1,inf); solve(0,inf);
if(num[1]+num[0]!=n-1||num[0]>K){
cout<<"no solution"<<endl;
return 0;
}
top=0;
num[0]=num[1]=0;
for(int i=1;i<=n;i++){
fa[i]=i;
}
for(int i=1;i<=m;i++){
if(c[i]==0&&mark[i]){
int p=find(u[i]),q=find(v[i]);
if(q!=p){
num[0]++;
fa[p]=q;
au[++top]=u[i];
av[top]=v[i];
ac[top]=c[i];
}
}
}
solve(0,K); solve(1,inf);
if(num[0]<K){
cout<<"no solution"<<endl;
return 0;
}
for(int i=1;i<=top;i++){
cout<<au[i]<<" "<<av[i]<<" "<<ac[i]<<endl;
}
return 0;
}
/*
in:
5 7 2
1 3 0
4 5 1
3 2 0
5 3 1
4 3 0
1 2 1
4 2 1
out:
3 2 0
4 3 0
5 3 1
1 2 1
*/