import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ###################################################################### n, m, c = na() g = [[] for i in range(n)] for i in range(m): u,v,r,w = na() u -= 1 v -= 1 g[u].append((v,r,w)) g[v].append((u,r,w)) visited = [[0] * (c+1) for i in range(n)] ans = -1 for C in range(1, c+1): visited[0][C] = 1 q = [(0,C)] while q: u,cc = q.pop(0) #print(u, cc) if u == n-1: ans = max(ans, cc) for v,r,w in g[u]: nc = cc - cc// r - w if nc >= 0 and not visited[v][nc]: visited[v][nc] = 1 q.append((v,nc)) print(ans)