#include <bits/stdc++.h>
using namespace std;
ifstream f("dmin.in");
ofstream g("dmin.out");
vector <double> d;
int n, m, i, j, k, x, ans[1502], MOD = 104659;
double EPS = 1e-10;
vector <pair<int, double>> a[1502];
bool v[1502];
void dijkstra(int nod) {
priority_queue <pair<double, int>, vector<pair<double,int>>, greater<pair<double, int>>> q;
q.push({0, nod});
d[nod] = 0;
ans[nod] = 1;
while (!q.empty()) {
int x = q.top().second;
q.pop();
if (v[x])
continue;
v[x] = 1;
for (auto it : a[x]) {
if ((d[x] + it.second) < d[it.first] - EPS) {
d[it.first] = d[x] + it.second;
ans[it.first] = ans[x];
q.push({d[it.first], it.first});
}
else if (fabs(d[x] + it.second - d[it.first]) <= EPS)
ans[it.first] = (ans[it.first] + ans[x]) % MOD;
}
}
}
int main()
{
f >> n >> m;
d.resize(n + 1, 1e18);
while (m--) {
f >> i >> j >> x;
a[i].emplace_back(j, log(x));
a[j].emplace_back(i, log(x));
}
dijkstra(1);
for (int i = 2; i <= n; i++)
g << ans[i] << " ";
return 0;
}