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