from collections import deque,defaultdict import heapq N,M,X=map(int,input().split()) G=[[] for _ in range(N)] C=defaultdict(int) T=defaultdict(int) for _ in range(M): u,v,c,t=map(int,input().split()) u-=1;v-=1 G[u].append(v) G[v].append(u) C[(u,v)]=c C[(v,u)]=c T[(u,v)]=t T[(v,u)]=t vis=[(1<<60,1<<60,1<<60) for _ in range(N)] # t,c,m attr=defaultdict(tuple) hq=[] heapq.heapify(hq) hq.append((0,0,0,0)) # t,c,m,nxt while hq: t,c,m,now=heapq.heappop(hq) vis[now]=(t,c,m) if now==N-1:break for nxt in G[now]: work=0 if c+C[(now,nxt)]>m: work=(m-c+C[(now,nxt)]+X-1)//X if t+T[(now,nxt)]+work