#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;
vector<pair<int,double>> g[1505];
double dist[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;
double l = log((double)c);
g[x].push_back({y, l});
g[y].push_back({x, l});
}
for (int i = 1; i <= n; i++)
dist[i] = 1e18;
priority_queue<pair<double,int>, vector<pair<double,int>>, greater<pair<double,int>>> pq;
dist[1] = 0;
nr[1] = 1;
pq.push({0, 1});
while (!pq.empty())
{
int x = pq.top().second;
pq.pop();
if (viz[x]) continue;
viz[x] = true;
for (auto e : g[x])
{
int y = e.first;
double nd = dist[x] + e.second;
if (nd < dist[y] - EPS)
{
dist[y] = nd;
nr[y] = nr[x];
pq.push({nd, y});
}
else if (fabs(nd - dist[y]) < EPS)
{
nr[y] = (nr[y] + nr[x]) % MOD;
}
}
}
for (int i = 2; i <= n; i++)
fout << nr[i] << ' ';
return 0;
}