#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const int MOD = 104659;
const long double INF = 1e100L;
const long double EPS = 1e-12L;
struct Edge
{
int to;
int cost;
};
struct State
{
int node;
long double dist;
bool operator>(const State& other) const
{
return dist > other.dist;
}
};
int main()
{
int N, M;
fin >> N >> M;
vector<vector<Edge>> adj(N + 1);
for (int i = 1; i <= M; i++)
{
int x, y, c;
fin >> x >> y >> c;
adj[x].push_back({y, c});
adj[y].push_back({x, c});
}
vector<long double> dist(N + 1, INF);
vector<int> ways(N + 1, 0);
priority_queue<State, vector<State>, greater<State>> pq;
dist[1] = 1;
ways[1] = 1;
pq.push({1, 1});
while (!pq.empty())
{
State current = pq.top();
pq.pop();
int u = current.node;
if (current.dist > dist[u] * (1 + EPS))
{
continue;
}
for (int i = 0; i < (int)adj[u].size(); i++)
{
int v = adj[u][i].to;
int c = adj[u][i].cost;
long double newDist = dist[u] * c;
if (newDist < dist[v] * (1 - EPS))
{
dist[v] = newDist;
ways[v] = ways[u];
pq.push({v, newDist});
}
else if (newDist <= dist[v] * (1 + EPS))
{
ways[v] = (ways[v] + ways[u]) % MOD;
}
}
}
for (int i = 2; i <= N; i++)
{
fout << ways[i] << " ";
}
fout << '\n';
return 0;
}