#include <bits/stdc++.h>
using namespace std;
const int MOD = 104659;
const long double INF = 1e30L;
const long double EPS = 1e-12L;
int main() {
ifstream fin("dmin.in");
ofstream fout("dmin.out");
int n, m, i, x, y, nr;
long long c;
long double w, cost, nd;
vector<long double> d;
vector<int> nrDrumuri;
vector<vector<pair<int, long double>>> g;
priority_queue<
pair<long double, int>,
vector<pair<long double, int>>,
greater<pair<long double, int>>
> pq;
fin >> n >> m;
g.resize(n + 1);
d.assign(n + 1, INF);
nrDrumuri.assign(n + 1, 0);
for ( i = 1; i <= m; i++ ) {
fin >> x >> y >> c;
w = logl( (long double)c );
g[x].push_back({y, w});
g[y].push_back({x, w});
}
d[1] = 0;
nrDrumuri[1] = 1;
pq.push({0, 1});
while ( !pq.empty() ) {
cost = pq.top().first;
x = pq.top().second;
pq.pop();
if ( cost <= d[x] + EPS ) {
for ( i = 0; i < (int)g[x].size(); i++ ) {
y = g[x][i].first;
w = g[x][i].second;
nd = cost + w;
if ( nd < d[y] - EPS ) {
d[y] = nd;
nrDrumuri[y] = nrDrumuri[x];
pq.push({nd, y});
} else if ( fabsl(nd - d[y]) <= EPS ) {
nrDrumuri[y] = (nrDrumuri[y] + nrDrumuri[x]) % MOD;
}
}
}
}
for ( i = 2; i <= n; i++ ) {
fout << nrDrumuri[i] << ' ';
}
fout << '\n';
return 0;
}