#include <fstream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
ifstream fin("dmin.in");
ofstream fout("dmin.out");
const int NMAX = 1505;
const int MOD = 104659;
const double INF = 1e18;
const double EPS = 1e-9;
vector<pair<int, double>> G[NMAX];
double dist[NMAX];
int cnt[NMAX];
bool used[NMAX];
void dijkstra(int start, int n) {
for (int i = 1; i <= n; i++) {
dist[i] = INF;
cnt[i] = 0;
used[i] = false;
}
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
dist[start] = 0;
cnt[start] = 1;
pq.push({0, start});
while (!pq.empty()) {
int node = pq.top().second;
pq.pop();
if (!used[node]) {
used[node] = true;
for (int i = 0; i < G[node].size(); i++) {
int vecin = G[node][i].first;
double cost = G[node][i].second;
// am gasit un drum strict mai bun
if (dist[node] + cost < dist[vecin] - EPS) {
dist[vecin] = dist[node] + cost;
cnt[vecin] = cnt[node];
pq.push({dist[vecin], vecin});
}
// am gasit un drum egal cu minimul
else if (fabs(dist[node] + cost - dist[vecin]) <= EPS) {
cnt[vecin] = (cnt[vecin] + cnt[node]) % MOD;
}
}
}
}
}
int main() {
int n, m;
fin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y, c;
fin >> x >> y >> c;
double w = log(c); // transformam produsul in suma
G[x].push_back({y, w});
G[y].push_back({x, w});
}
dijkstra(1, n);
for (int i = 2; i <= n; i++) {
fout << cnt[i] << " ";
}
fout << "\n";
return 0;
}