from heapq import heappop, heappush n = int(input()) c = int(input()) v = int(input()) L = [list(map(int,input().split())) for i in range(4)] e = [[] for i in range(n)] for s,t,y,m in zip(L[0],L[1],L[2],L[3]): s -= 1 t -= 1 e[s].append((t,y,m)) e[t].append((s,y,m)) inf = 10**10 dis = [[inf]*(c+1) for i in range(n)] dis[0][c] = 0 q = [(0,0,c)] while q: time,now,d = heappop(q) if time > dis[now][d]: continue for nex,y,m in e[now]: if d >= y and dis[nex][d-y] > dis[now][d]+m: dis[nex][d-y] = dis[now][d]+m heappush(q, (dis[nex][d-y],nex,d-y)) ans = min(dis[-1]) if ans == inf: ans = -1 print(ans)