#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
int main()
{
freopen("dmin.in", "r", stdin);
freopen("dmin.out", "w", stdout);
int n, m;
scanf("%d %d", &n, &m);
vector<vector<pair<int, double>>> g(n + 1);
for (int i = 0; i < m; i++)
{
int x, y, c;
scanf("%d %d %d", &x, &y, &c);
g[x].push_back({y, log((double)c)});
g[y].push_back({x, log((double)c)});
}
vector<double> d(n + 1, 1e18);
vector<int> nr(n + 1, 0);
vector<int> gata(n + 1, 0);
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
d[1] = 0;
nr[1] = 1;
pq.push({0, 1});
while (!pq.empty())
{
int x = pq.top().second;
pq.pop();
if (gata[x])
continue;
gata[x] = 1;
for (int i = 0; i < (int)g[x].size(); i++)
{
int y = g[x][i].first;
double nd = d[x] + g[x][i].second;
if (nd < d[y] - 1e-9)
{
d[y] = nd;
nr[y] = nr[x];
pq.push({d[y], y});
}
else if (fabs(nd - d[y]) < 1e-9)
nr[y] = (nr[y] + nr[x]) % 104659;
}
}
for (int i = 2; i <= n; i++)
printf("%d ", nr[i]);
printf("\n");
return 0;
}