#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "dmin";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;
typedef pair<int, double> PID;
typedef pair<double, int> PDI;
const int INF = (1LL << 30) - 1;
const lld LINF = (1LL << 60) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int NMAX = 1500 + 5;
const int MOD = 104659;
const double EPS = 1e-9;
int N, M;
vector<PID> V[NMAX];
int sol[NMAX];
double D[NMAX];
bitset<NMAX> viz;
priority_queue<PDI, vector<PDI>, greater<PDI> > PQ;
int comp(double a, double b) {
if(fabs(a - b) < EPS)
return 0;
if(fabs(a - b) / (a - b) > EPS)
return 1;
return -1;
}
void dijkstra(int x) {
int i, y;
lld z;
for(i = 2; i <= N; i++)
D[i] = INF;
D[x] = 0.0;
PQ.push(make_pair(D[x], x));
sol[x] = 1;
while(!PQ.empty()) {
x = PQ.top().second;
PQ.pop();
if(viz[x])
continue;
viz[x] = 1;
for(auto nod : V[x]) {
y = nod.first;
z = nod.second;
if(comp(D[y], D[x] + z) > 0) {
D[y] = D[x] + z;
PQ.push(make_pair(D[y], y));
sol[y] = 0;
}
if(comp(D[y], D[x] + z) == 0)
sol[y] = (sol[y] + sol[x]) % MOD;
}
}
}
int main() {
int i, x, y, z;
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
scanf("%d%d", &N, &M);
while(M--) {
scanf("%d%d%lld", &x, &y, &z);
V[x].push_back(make_pair(y, log(z)));
V[y].push_back(make_pair(x, log(z)));
}
dijkstra(1);
for(i = 2; i <= N; i++)
printf("%d ", sol[i]);
return 0;
}