#include <fstream>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
ifstream fin("dmin.in");
ofstream gout("dmin.out");
vector<pair<int,double>> graf[1505];
double dist[1505];
int nr[1505];
bool gata[1505];
const int mod = 104659;
const double EPS = 1e-10;
int main() {
int N,M;
fin>>N>>M;
for(int i=0;i<M;i++) {
int x,y,cost;
fin>>x>>y>>cost;
double w = log((double) cost);
graf[x].push_back({y,w});
graf[y].push_back({x,w});
}
for(int i=1;i<=N;i++) dist[i] = 1<<30;
dist[1] = 0;
nr[1] = 1;
priority_queue<pair<double,int>, vector<pair<double,int>>, greater<pair<double,int>>> pq;
pq.push({0,1});
while(!pq.empty()) {
int v = pq.top().second;
pq.pop();
if(gata[v]) continue;
gata[v] = 1;
for(auto e: graf[v]) {
int u = e.first;
double nd = dist[v] + e.second;
if(nd < dist[u] -EPS) {
dist[u] = nd;
nr[u] = nr[v];
pq.push({nd,u});
} else if(fabs(nd - dist[u])<EPS) {
nr[u] = (nr[u]+nr[v]) % mod;
}
}
}
for(int i=2;i<=N;i++) gout<<nr[i]<<" ";
return 0;
}