#include <bits/stdc++.h>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const int MOD = 104659;
const double EPS = 1e-9;
vector<pair<int, double>> v[1505];
double d[1505];
int nr[1505];
bool viz[1505];
int main()
{
int n, m;
fin >> n >> m;
for (int i = 1; i <= m; i++)
{
int x, y, c;
fin >> x >> y >> c;
v[x].push_back(make_pair(y, log((double)c)));
v[y].push_back(make_pair(x, log((double)c)));
}
for (int i = 1; i <= n; i++)
d[i] = 1e18;
d[1] = 0;
nr[1] = 1;
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
pq.push(make_pair(0.0, 1));
while (!pq.empty())
{
int x = pq.top().second;
pq.pop();
if (viz[x])
continue;
viz[x] = true;
for (int i = 0; i < (int)v[x].size(); i++)
{
int y = v[x][i].first;
double c = v[x][i].second;
double nou = d[x] + c;
if (nou < d[y] - EPS)
{
d[y] = nou;
nr[y] = nr[x];
pq.push(make_pair(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;
}