from heapq import * n, m = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): a, b, c, x = map(int, input().split()) a -= 1 b -= 1 edges[a].append((b, c, x)) edges[b].append((a, c, x)) inf = 1 << 60 dist = [[inf] * 2 for _ in range(n)] def f(d, pos, x_): return (d * n + pos) * 2 + x_ hq = [f(0, n - 1, 0)] while hq: tmp = heappop(hq) x_ = tmp % 2 tmp //= 2 d = tmp // n pos = tmp - d * n if dist[pos][x_] < d: continue for npos, c, x in edges[pos]: nd = d + c nx = x_ | x if dist[npos][nx] > nd: dist[npos][nx] = nd heappush(hq, f(nd, npos, nx)) for i in range(n - 1): print(dist[i][1])