// https://infoarena.ro/problema/dmin
#include <bits/stdc++.h>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const int NMAX=1e5+8;
const long long mod=104659;
int n,m;
vector<pair<int,int> > g[NMAX];
long double dist[NMAX];
long long dp[NMAX];
int main() {
ios_base::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
fin >> n >> m;
for(int i=1; i<=m; i++) {
int x,y,w;
fin >> x >> y >> w;
g[x].push_back({y,w});
g[y].push_back({x,w});
}
for(int i=1; i<=n; i++) {
dist[i]=LDBL_MAX;
}
queue<int> q; q.push(1);
dp[1]=1;
dist[1]=0.0;
while(!q.empty()) {
int nod=q.front();
q.pop();
for(const auto &[vec,w]:g[nod]) {
if(dist[vec]>dist[nod]+log2(w)) {
dist[vec]=dist[nod]+log2(w);
dp[vec]=dp[nod];
q.push(vec);
}
else if(dist[vec]==dist[nod]+log2(w)) {
dp[vec]=(dp[vec]+dp[nod])%mod;
}
}
}
for(int i=2; i<=n; i++) {
fout << dp[i] << " ";
}
fout << "\n";
return 0;
}