#include <bits/stdc++.h>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const int nmax = 1505;
const int MOD = 104659;
const double EPS = 1e-9;
vector<vector<pair<int, int>>> graf(nmax);
int n, m, x, y, c, cnt[nmax];
double dDij[nmax];
void dijkstraNr(int s) {
for (int i = 1; i <= n; i++) {
dDij[i] = 1e18;
cnt[i] = 0;
}
dDij[s] = 0;
cnt[s] = 1;
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
q.push({0, s});
while (!q.empty()) {
int nod = q.top().second;
double val = q.top().first;
q.pop();
if (val > dDij[nod] + EPS) {
continue;
}
for (auto pereche : graf[nod]) {
int vecin = pereche.first;
double w = log((double)pereche.second);
double nou = dDij[nod] + w;
if (nou < dDij[vecin] - EPS) {
dDij[vecin] = nou;
cnt[vecin] = cnt[nod];
q.push({nou, vecin});
}
else if (fabs(nou - dDij[vecin]) <= EPS) {
cnt[vecin] = (cnt[vecin] + cnt[nod]) % MOD;
}
}
}
}
int main() {
fin >> n >> m;
for (int i = 0; i < m; ++i) {
fin >> x >> y >> c;
graf[x].push_back({y, c});
graf[y].push_back({x, c});
}
dijkstraNr(1);
for (int i = 2; i <= n; i++) {
fout << cnt[i] << " ";
}
fout << "\n";
return 0;
}