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