R=range J=lambda:map(int,input().split()) N,M,C=J() C+=1 e=[[]for i in R(N)] f=[[[]]*N for i in R(N)] for m in R(M): i,j,r,w=J() e[i-1]+=[j-1] e[j-1]+=[i-1] f[i-1][j-1]=[max(-1,c-c//r-w)for c in R(C)] f[j-1][i-1]=f[i-1][j-1][:] u=[[1]*C for i in R(N)] for c in R(1,C): q,l,r=[[0,c]],0,C while len(q): i,d=q.pop(-1) if d>=0 and u[i][d]: u[i][d]=0 for j in e[i]:q+=[[j,f[i][j][d]]] if u[N-1][0]:l=r=-1 while l+1