#include <iostream>
#include <fstream>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;
const int mod = 104659;
const double eps=1e-10;
const double inf=1e30;
std::vector<std::vector<std::pair<int,double>>> graf;
std::vector<double> dist;
std::vector<int> nr;
void dijkstra(int node){
std::priority_queue<std::pair<double,int> , vector<std::pair<double,int>> , greater<std::pair<double,int>>> q;
q.push({0,node});
dist[node]=0;
nr[node]=1;
while(!q.empty()){
double d = q.top().first;
int u = q.top().second;
q.pop();
if(d>dist[u]+eps)
continue;
for(auto [v,c]:graf[u]){
if(dist[u]+c<dist[v]-eps){
dist[v]=dist[u]+c;
nr[v]=nr[u];
q.push({dist[v],v});
}
else if(fabs(dist[u]+c-dist[v])<eps){
nr[v]=(nr[v]+nr[u])%mod;
}
}
}
}
int main() {
ifstream fin("dmin.in");
ofstream fout("dmin.out");
int n, m;
fin >> n >> m;
graf.resize(n + 1);
dist.resize(n + 1, inf);
nr.resize(n + 1, 0);
for (int i = 0; i < m; i++) {
int x, y, c;
fin >> x >> y >> c;
graf[x].push_back({y, log(c)});
graf[y].push_back({x, log(c)});
}
dijkstra(1);
for (int i = 2; i <= n; i++)
fout<<nr[i]<< ' ';
fout<<'\n';
return 0;
}