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