N, M, C = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): u, v, c, w = map(int, input().split()) u, v = u - 1, v - 1 G[u].append((v, c, w)) G[v].append((u, c, w)) dp = [[10**18] * (C + 1) for _ in range(N)] for i in range(1, C + 1): dp[0][i] = i for c in range(C, -1, -1): for i in range(N): if not dp[i][c]: continue for u, r, w in G[i]: nc = c - (c//r) - w if nc < 0: continue dp[u][nc] = min(dp[u][nc], dp[i][c]) ans = [-1] * (C + 1) pre = 10**18 for i in range(C + 1): for j in range(pre, min(C + 1, dp[-1][i])): ans[j] = i - 1 pre = dp[-1][i] for a in ans[1:]: print(a)