#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
int n, m, x, y, c;
int nr[1501];
double dist[1501];
bool viz[1501];
const int MOD = 104659;
const double EPS = 1e-9;
vector<pair<int,double>> graf[1501];
void dijkstra(int s) {
priority_queue<pair<double,int>,
vector<pair<double,int>>,
greater<>> pq;
for (int i = 1; i <= n; i++) {
dist[i] = 1e18;
nr[i] = 0;
}
dist[s] = 0;
nr[s] = 1;
pq.push({0, s});
while (!pq.empty()) {
int nod = pq.top().second;
pq.pop();
if (viz[nod]) continue;
viz[nod] = true;
for (auto [vecin, cost] : graf[nod]) {
double nou = dist[nod] + cost;
if (nou < dist[vecin] - EPS) {
dist[vecin] = nou;
nr[vecin] = nr[nod];
pq.push({dist[vecin], vecin});
}
else if (abs(nou - dist[vecin]) < EPS) {
nr[vecin] = (nr[vecin] + nr[nod]) % MOD;
}
}
}
}
int main() {
fin >> n >> m;
for (int i = 1; i <= m; i++) {
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] << " ";
}
return 0;
}