#include <bits/stdc++.h>
using namespace std;
const int MAXIM = 1505;
const int MOD = 104659;
const long double INF = 1e100L;
const long double EPS = 1e-10L;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
vector<pair<int, long double>> graf[MAXIM];
long double dist[MAXIM];
int cnt[MAXIM];
bool vis[MAXIM];
void dijkstra(const int start, const int n) {
using State = pair<long double, int>;
priority_queue<State, vector<State>, greater<State>> pq;
fill(dist + 1, dist + n + 1, INF);
fill(cnt + 1, cnt + n + 1, 0);
fill(vis + 1, vis + n + 1, false);
dist[start] = 0.0L;
cnt[start] = 1;
pq.push({0.0L, start});
while (!pq.empty()) {
const int u = pq.top().second;
pq.pop();
if (vis[u]) {
continue;
}
vis[u] = true;
const long double d = dist[u];
for (const auto& [v, cost] : graf[u]) {
const long double newDist = d + cost;
if (newDist < dist[v] - EPS) {
dist[v] = newDist;
cnt[v] = cnt[u];
pq.push({newDist, v});
} else if (fabsl(newDist - dist[v]) <= EPS) {
cnt[v] += cnt[u];
if (cnt[v] >= MOD) {
cnt[v] -= MOD;
}
}
}
}
}
int main() {
int n, m;
fin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y, cost;
fin >> x >> y >> cost;
const long double logCost = logl(static_cast<long double>(cost));
graf[x].push_back({y, logCost});
graf[y].push_back({x, logCost});
}
dijkstra(1, n);
for (int i = 2; i <= n; i++) {
if (i > 2) {
fout << ' ';
}
fout << cnt[i];
}
}