#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const long double INF = 1e18;
const int MOD = 104659;
const long double EPS = 1e-12;
struct Muchie {
int to;
long double cost; // log(c)
};
int main() {
int N, M;
fin >> N >> M;
vector<vector<Muchie>> adj(N + 1);
for (int i = 0; i < M; ++i) {
int x, y;
long long c;
fin >> x >> y >> c;
long double l = logl((long double)c);
adj[x].push_back({y, l});
adj[y].push_back({x, l});
}
vector<long double> dist(N + 1, INF);
vector<int> ways(N + 1, 0);
priority_queue<pair<long double, int>,
vector<pair<long double, int>>,
greater<pair<long double, int>>> pq;
dist[1] = 0;
ways[1] = 1;
pq.push({0, 1});
while (!pq.empty()) {
long double d = pq.top().first;
int u = pq.top().second;
pq.pop();
if (d > dist[u] + EPS) continue;
for (auto& e : adj[u]) {
int v = e.to;
long double nd = dist[u] + e.cost;
if (nd < dist[v] - EPS) {
dist[v] = nd;
ways[v] = ways[u];
pq.push({nd, v});
} else if (fabsl(nd - dist[v]) <= EPS) {
ways[v] = (ways[v] + ways[u]) % MOD;
}
}
}
for (int i = 2; i <= N; ++i)
fout << ways[i] << " ";
fout << "\n";
}