import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int h = sc.nextInt(); int w = sc.nextInt(); int k = sc.nextInt(); int t = Math.min(sc.nextInt(), h * w - 1); int[][] times = new int[h][w]; int[][] values = new int[h][w]; for (int i = 0; i < k; i++) { int r = sc.nextInt() - 1; int c = sc.nextInt() - 1; int a = sc.nextInt(); int b = sc.nextInt(); times[r][c] = a - 1; values[r][c] = b; } long[][][] costs = new long[h][w][h * w * 2]; for (long[][] arr1 : costs) { for (long[] arr2 : arr1) { Arrays.fill(arr2, Long.MAX_VALUE); } } PriorityQueue queue = new PriorityQueue<>(); queue.add(new Path(0, 0, h * w, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.r][p.c][p.time] <= p.value) { continue; } costs[p.r][p.c][p.time] = p.value; if (p.r < h - 1) { queue.add(new Path(p.r + 1, p.c, p.time + 1, p.value)); } if (p.c < w - 1) { queue.add(new Path(p.r, p.c + 1, p.time + 1, p.value)); } queue.add(new Path(p.r, p.c, Math.max(0, p.time - times[p.r][p.c]), p.value + values[p.r][p.c])); } long ans = Long.MAX_VALUE; for (int i = h * w + t; i >= 0; i--) { ans = Math.min(ans, costs[h - 1][w - 1][i]); } System.out.println(Arrays.toString(costs[h - 1][w - 1])); System.out.println(ans); } static class Path implements Comparable { int r; int c; int time; long value; public Path(int r, int c, int time, long value) { this.r = r; this.c = c; this.time = time; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return - 1; } else { return 1; } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }