R=range J=lambda:map(int,input().split()) N,M,C=J() C+=1 W=[[[]]*N for i in R(N)] for m in R(M): i,j,r,w=J() W[i-1][j-1]=[max(-1,c-c//r-w)for c in R(C)] W[j-1][i-1]=W[i-1][j-1][:] for k in R(N): for i in R(N): if W[i][k]!=[]and i!=k: for j in R(N): if W[k][j]!=[]and i!=j and k!=j: t=[-1if W[i][k][c]<0else W[k][j][W[i][k][c]]for c in R(C)] if W[i][j]==[]:W[i][j]=t else:W[i][j]=[max(W[i][j][c],t[c])for c in R(C)] for c in R(1,C):print(-1if W[0][N-1]==[]else W[0][N-1][c])