Identify the time complexity of the following code as constant, linear, quadratic, cubic, log(n), nlog(n) or NP-hard. //package round718;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Queue;

public class D2 {
	InputStream is;
	FastWriter out;
	String INPUT = "";//2 5 9 9 9 9 9 8 8 8 8 5 6 7 8 9";

	void solve()
	{
		int n = ni(), m = ni(), K = ni();
		int[][] a = new int[2*n+1][2*m+1];
		for(int i = 0;i < n;i++){
			int[] u = na(m-1);
			for(int j = 0;j < m-1;j++){
				a[2*i][2*j+1] = u[j];
			}
		}
		for(int i = 0;i < n-1;i++){
			int[] u = na(m);
			for(int j = 0;j < m;j++){
				a[2*i+1][2*j] = u[j];
			}
		}
		if(K % 2 == 1){
			for(int i = 0;i < n;i++){
				for(int j = 0;j < m;j++){
					out.print(-1 + " ");
				}
				out.println();
			}
			return;
		}

		int[][][] dp = new int[K/2+1][n][m];
		int[] dr = {1, 0, -1, 0};
		int[] dc = {0, 1, 0, -1};
		for(int i = 1;i <= K/2;i++){
			for(int j = 0;j < n;j++){
				for(int k = 0;k < m;k++){
					dp[i][j][k] = Integer.MAX_VALUE;
					for(int l = 0;l < 4;l++){
						int jj = j + dr[l], kk = k + dc[l];
						if(jj >= 0 && jj < n && kk >= 0 && kk < m){
							dp[i][j][k] = Math.min(dp[i][j][k], dp[i-1][jj][kk] + a[j+jj][k+kk]);
						}
					}
				}
			}
		}

		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				out.print(dp[K/2][i][j] * 2 + " ");
			}
			out.println();
		}
	}
	
	void run() throws Exception
	{
//		int n = 500, m = 500;
//		Random gen = new Random();
//		StringBuilder sb = new StringBuilder();
//		sb.append(n + " ");
//		sb.append(n + " ");
//		sb.append(20 + " ");
//		for (int i = 0; i < n; i++) {
//			for(int j = 0;j < m-1;j++) {
//				sb.append(gen.nextInt(200000) + " ");
//			}
//		}
//		for (int i = 0; i < n-1; i++) {
//			for(int j = 0;j < m;j++) {
//				sb.append(gen.nextInt(200000) + " ");
//			}
//		}
//		INPUT = sb.toString();


		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new FastWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void... Complexity: