""" N,M が小さいんだよな つまり、Tが大きい場合は無視で構わない 後は… dp[x][y][T] = x,y に時刻Tで居る為に必要な最小コスト で良いか 時刻は, T-(N-1-M-1) -200 ~ T 位まで考慮しておけばいいかな """ import sys from sys import stdin import heapq N,M,K,T = map(int,stdin.readline().split()) AB_to_CD = [[None] * M for i in range(N)] for i in range(K): A,B,C,D = map(int,stdin.readline().split()) A -= 1 B -= 1 AB_to_CD[A][B] = (C,D) dp = [[[float("inf")] * 500 for i in range(M)] for j in range(N)] dp[0][0][0] = 0 q = [ (0,0,0,0) ] while q: cost,x,y,t = heapq.heappop(q) if (x,y) == (N-1,M-1) and t <= T: print (cost) sys.exit() if dp[x][y][t] != cost: continue if t <= N+M+10: for nx,ny in ( (x+1,y),(x-1,y),(x,y-1),(x,y+1) ): if 0 <= nx < N and 0 <= ny < M and dp[nx][ny][t+1] > dp[x][y][t]: dp[nx][ny][t+1] = dp[x][y][t] heapq.heappush( q,(dp[nx][ny][t+1] , nx , ny , t+1) ) if AB_to_CD[x][y] != None: C,D = AB_to_CD[x][y] nexT = max(-200 , t-C+1) if dp[x][y][nexT] > D + dp[x][y][t]: dp[x][y][nexT] = D + dp[x][y][t] heapq.heappush( q,(dp[x][y][nexT] , x , y , nexT) ) print (-1)