#include <bits/stdc++.h>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
double INF = DBL_MAX / 4;
int main() {
int n, m;
fin >> n >> m;
vector<vector<pair<int, double>>> graph(n + 1);
for (int i = 0; i < m; i++) {
int x, y, c;
fin >> x >> y >> c;
double w = log(c);
graph[x].push_back({y, w});
graph[y].push_back({x, w});
}
vector<double> d(n + 1, INF);
vector<int> cnt(n + 1, 0);
vector<bool> viz(n + 1, false);
double eps = 0.0000000001;
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
d[1] = 0;
cnt[1] = 1;
pq.push({0, 1});
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
if (viz[u]) {
continue;
}
viz[u] = true;
for (size_t i = 0; i < graph[u].size(); i++) {
int v = graph[u][i].first;
double w = graph[u][i].second;
double new_d = d[u] + w;
if (new_d < d[v] - eps) {
d[v] = new_d;
cnt[v] = cnt[u];
pq.push({d[v], v});
} else if (fabs(new_d - d[v]) <= eps) {
cnt[v] = (cnt[v] + cnt[u]) % 104659;
}
}
}
for (int i = 2; i <= n; i++) {
fout << cnt[i] << " ";
}
fout << "\n";
return 0;
}