#include <bits/stdc++.h>
using namespace std;
const int MOD = 104659;
const double INF = 1e18;
const double EPS = 1e-10;
int main() {
ifstream fin("dmin.in");
ofstream fout("dmin.out");
int n, m;
fin >> n >> m;
vector<vector<pair<int, double>>> graf(n + 1);
for (int i = 1; i <= m; i++) {
int x, y, cost;
fin >> x >> y >> cost;
double costNou = log((double)cost);
graf[x].push_back({y, costNou});
graf[y].push_back({x, costNou});
}
vector<double> dist(n + 1, INF);
vector<int> nr(n + 1, 0);
priority_queue<
pair<double, int>,
vector<pair<double, int>>,
greater<pair<double, int>>
> pq;
dist[1] = 0;
nr[1] = 1;
pq.push({0, 1});
while (!pq.empty()) {
double cost = pq.top().first;
int nod = pq.top().second;
pq.pop();
if (cost > dist[nod] + EPS)
continue;
for (auto muchie : graf[nod]) {
int vecin = muchie.first;
double costMuchie = muchie.second;
double costNou = dist[nod] + costMuchie;
if (costNou < dist[vecin] - EPS) {
dist[vecin] = costNou;
nr[vecin] = nr[nod];
pq.push({costNou, vecin});
}
else if (abs(costNou - dist[vecin]) <= EPS) {
nr[vecin] += nr[nod];
nr[vecin] %= MOD;
}
}
}
for (int i = 2; i <= n; i++) {
fout << nr[i] << " ";
}
fout << '\n';
return 0;
}