from collections import * from itertools import * from functools import * from heapq import * import sys,math sys.setrecursionlimit(3*10**5) input = sys.stdin.readline INF = (1<<60) N,M,X = map(int,input().split()) e = [[] for _ in range(N)] for _ in range(M): u,v,a,b = map(int,input().split()) u -= 1 v -= 1 e[u].append((v,a,b)) e[v].append((u,a,b)) def dijkstra(s,e,t): N = len(e) dist = [INF]*N dist[s]=0 h = [] heappush(h,(0,s)) while h: nw,v = heappop(h) if dist[v]!=nw: continue for iv,ic,iw in e[v]: if iw1: mid = (y+x)//2 if is_ok(mid): x = mid else: y = mid print(x)