//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    private static ArrayDeque<Integer>[][] edge;
    private static long[][] dp[],w1,w2;
    private static int N,M,K;

    private static void answer()
    {
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<N;i++)
        {
            for (int j = 0; j < M; j++) sb.append(dp[i][j][K]).append(" ");
            sb.append("\n");
        }
        System.out.println(sb);
    }
    private static long solve(int i, int j, int pos)
    {
        if(pos==0) return 0;
        if(dp[i][j][pos]!=-1) return dp[i][j][pos];

        long a=Long.MAX_VALUE/100;
        if(i-1>=0) a=Math.min(a,solve(i-1,j,pos-1)+w2[i-1][j]);
        if(i<N-1) a=Math.min(a,solve(i+1,j,pos-1)+w2[i][j]);
        if(j-1>=0) a=Math.min(a,solve(i,j-1,pos-1)+w1[i][j-1]);
        if(j<M-1) a=Math.min(a,solve(i,j+1,pos-1)+w1[i][j]);

        return dp[i][j][pos]=a;
    }
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i;

        String[] s=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        M=Integer.parseInt(s[1]);
        K=Integer.parseInt(s[2]);

        edge=new ArrayDeque[N][M];
        for(i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
                edge[i][j]=new ArrayDeque<>();
        }

        w1=new long[N][M-1];
        w2=new long[N-1][M];
        dp=new long[N][M][K/2+1];

        for(i=0;i<N;i++)
        {
            s=br.readLine().trim().split(" ");
            for(int j=0;j<M-1;j++) w1[i][j]=Integer.parseInt(s[j])*2L;
        }
        for(i=0;i<N-1;i++)
        {
            s=br.readLine().trim().split(" ");
            for(int j=0;j<M;j++) w2[i][j]=Integer.parseInt(s[j])*2L;
        }

        for(i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
                Arrays.fill(dp[i][j],-1);
        }

        if(K%2==1)
        {
            K/=2;
            answer();
            System.exit(0);
        }

        K/=2;
        for(i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
                solve(i,j,K);
        }

        answer();
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main

{
	 static FastReader sc=new FastReader();
	 static long dp[][][];
	 static int mod=1000000007;

	  public static void main(String[] args)  throws IOException
{
		    //CHECK FOR N=1
       	//CHECK FOR N=1
	    //CHECK FOR N=1
       	//CHECK FOR N=1

		   PrintWriter out=new PrintWriter(System.out);
		  // StringBuffer sb=new StringBuffer("");
		  int ttt=1;
		//  ttt =i();

	        outer :while (ttt-- > 0)
			{

	        	int n=i();
	        	int m=i();
	        	int k=i();
	        	int A[][]=input(n,m-1);
	        	int B[][]=input(n-1, m);
	        	dp=new long[n+1][m+1][k+1];
	        	for(int ii=0;ii<n;ii++) {
	        		for(int jj=0;jj<m;jj++) {
	        			Arrays.fill(dp[ii][jj],-1);
	        		}
	        	}
	        	if(k%2!=0) {
	        		for(int i=0;i<n;i++) {
	        			for(int j=0;j<m;j++) {
	        				System.out.print("-1 ");
	        			}
	        			System.out.println();
	        		}
	        	}
	        	else {
	        	go(A, B, 0, 0, k/2, n, m);
	        	for(int i=0;i<n;i++) {
        			for(int j=0;j<m;j++) {
        				System.out.print(dp[i][j][k/2]*2+" ");
        			}
        			System.out.println();
        		}
	        	}

			}
		     out.close();
    	//System.out.println(sb.toString());

	    //CHECK FOR N=1                    //CHECK FOR M=0
        //CHECK FOR N=1                    //CHECK FOR M=0
       	//CHECK FOR N=1
       	//CHECK FOR N=1
       	//CHECK FOR N=1

    }
	  static long go(int A[][],int B[][],int i,int j,int k,int l,int p) {
		 if(k==0)
			 return 0;
		 if(i>=l || j>=p)
			 return Integer.MAX_VALUE;
		  if(dp[i][j][k]!=-1)
			  return dp[i][j][k];
//		  if(i==m && j==n && k<org) {
//			  return Integer.MAX_VALUE;
//		  }
		  long op1=Long.MAX_VALUE;
		  if(i+1<l)
		  op1=Math.min(op1,go(A, B, i+1, j, k-1,l,p)+B[i][j]);
		  if(i-1>=0)
		 op1=Math.min(op1,go(A, B, i-1, j, k-1,l,p)+B[i-1][j]);
		  if(j+1<p)
		  op1=Math.min(op1,go(A, B, i, j+1, k-1,l,p)+A[i][j]);
		  if(j-1>=0)
		   op1=Math.min(op1,go(A, B, i, j-1, k-1,l,p)+A[i][j-1]);
		  go(A, B, i+1, j, k, l, p);
		  go(A, B, i, j+1, k, l, p);
		  return dp[i][j][k]=op1;
	  }

static int[] input(int n) {
	int A[]=new int[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.nextInt();
	   }
	   return A;
   }
static long[] inputL(int n) {
	long A[]=new long[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.nextLong();
	   }
	   return A;
   }
static String[] inputS(int n) {
	String A[]=new String[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.next();
	   }
	   return A;
   }
static long sum(int A[]) {
	long sum=0;
	for(int i : A) {
		sum+=i;
	}
	return sum;
}
static long sum(long A[]) {
	long sum=0;
	for(long i : A) {
		sum+=i;
	}
	return sum;
}
static void reverse(long A[]) {
	int n=A.length;
	long B[]=new long[n];
	for(int i=0;i<n;i++) {
		B[i]=A[n-i-1];
	}
	for(int i=0;i<n;i++)
		A[i]=B[i];

}
static void reverse(int A[]) {
	int n=A.length;
	int B[]=new int[n];
	for(int i=0;i<n;i++) {
		B[i]=A[n-i-1];
	}
	for(int i=0;i<n;i++)
		A[i]=B[i];

}
static void input(int A[],int B[]) {
	   for(int i=0;i<A.length;i++) {
		   A[i]=sc.nextInt();
		   B[i]=sc.nextInt();
	   }
}
static int[][] input(int n,int m){
	int A[][]=new int[n][m];
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			A[i][j]=i();
		}
	}
	return A;
}
static char[][] charinput(int n,int m){
	char A[][]=new char[n][m];
	for(int i=0;i<n;i++) {
		String s=s();
		for(int j=0;j<m;j++) {
			A[i][j]=s.charAt(j);
		}
	}
	return A;
}
static int max(int A[]) {
	int max=Integer.MIN_VALUE;
	for(int i=0;i<A.length;i++) {
		max=Math.max(max, A[i]);
	}
	return max;
}
static int min(int A[]) {
	int min=Integer.MAX_VALUE;
	for(int i=0;i<A.length;i++) {
		min=Math.min(min, A[i]);
	}
	return min;
}
static long max(long A[]) {
	long max=Long.MIN_VALUE;
	for(int i=0;i<A.length;i++) {
		max=Math.max(max, A[i]);
	}
	return max;
}
static long min(long A[]) {
	long min=Long.MAX_VALUE;
	for(int i=0;i<A.length;i++) {
		min=Math.min(min, A[i]);
	}
	return min;
}
static long [] prefix(long A[]) {
	long p[]=new long[A.length];
	p[0]=A[0];
	for(int i=1;i<A.length;i++)
		p[i]=p[i-1]+A[i];
	return p;
}
static long [] prefix(int A[]) {
	long p[]=new long[A.length];
	p[0]=A[0];
	for(int i=1;i<A.length;i++)
		p[i]=p[i-1]+A[i];
	return p;
}
static long [] suffix(long A[]) {
	long p[]=new long[A.length];
	p[A.length-1]=A[A.length-1];
	for(int i=A.length-2;i>=0;i--)
		p[i]=p[i+1]+A[i];
	return p;
}
static long [] suffix(int A[]) {
	long p[]=new long[A.length];
	p[A.length-1]=A[A.length-1];
	for(int i=A.length-2;i>=0;i--)
		p[i]=p[i+1]+A[i];
	return p;
}
static void print(int A[]) {
	for(int i : A) {
		System.out.print(i+" ");
	}
	System.out.println();
}
static void print(long A[]) {
	for(long i : A) {
		System.out.print(i+" ");
	}
	System.out.println();
}
static long mod(long x) {
	 int mod=1000000007;
	  return ((x%mod + mod)%mod);
}
static String reverse(String s) {
	StringBuffer p=new StringBuffer(s);
	p.reverse();
	return p.toString();
}

     static int i() {
    	 return sc.nextInt();
     }
     static String s() {
    	 return sc.next();
     }
     static long l() {
    	 return sc.nextLong();
     }
     static void sort(int[] A){
        int n = A.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            int tmp = A[i];
            int randomPos = i + rnd.nextInt(n-i);
            A[i] = A[randomPos];
            A[randomPos] = tmp;
        }
        Arrays.sort(A);
     }
     static void sort(long[] A){
	        int n = A.length;
	        Random rnd = new Random();
	        for(int i=0; i<n; ++i){
	            long tmp = A[i];
	            int randomPos = i + rnd.nextInt(n-i);
	            A[i] = A[randomPos];
	            A[randomPos] = tmp;
	        }
	        Arrays.sort(A);
	     }
  static String sort(String s) {
 	 Character ch[]=new Character[s.length()];
 	 for(int i=0;i<s.length();i++) {
 		 ch[i]=s.charAt(i);
 	 }
 	 Arrays.sort(ch);
 	 StringBuffer st=new StringBuffer("");
 	 for(int i=0;i<s.length();i++) {
 		 st.append(ch[i]);
 	 }
 	 return st.toString();
  }
  static HashMap<Integer,Integer> hash(int A[]){
	  HashMap<Integer,Integer> map=new HashMap<Integer, Integer>();
	  for(int i : A) {
		  if(map.containsKey(i)) {
			  map.put(i, map.get(i)+1);
		  }
		  else {
			  map.put(i, 1);
		  }
	  }
	  return map;
  }
  static TreeMap<Integer,Integer> tree(int A[]){
	  TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>();
	  for(int i : A) {
		  if(map.containsKey(i)) {
			  map.put(i, map.get(i)+1);
		  }
		  else {
			  map.put(i, 1);
		  }
	  }
	  return map;
  }
     static boolean prime(int n)
	    {
	        if (n <= 1)
	            return false;
	        if (n <= 3)
	            return true;
	        if (n % 2 == 0 || n % 3 == 0)
	            return false;
	        double sq=Math.sqrt(n);

	        for (int i = 5; i <= sq; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	                return false;
	        return true;
	    }
     static boolean prime(long n)
	    {
	        if (n <= 1)
	            return false;
	        if (n <= 3)
	            return true;
	        if (n % 2 == 0 || n % 3 == 0)
	            return false;
	        double sq=Math.sqrt(n);

	        for (int i = 5; i <= sq; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	                return false;
	        return true;
	    }
     static int gcd(int a, int b)
     {
         if (a == 0)
             return b;
         return gcd(b % a, a);
     }
     static long gcd(long a, long b)
     {
         if (a == 0)
             return b;
         return gcd(b % a, a);
     }
     static class Pair implements Comparable<Pair>
     {
    	 int x;
    	 int y;
    	 int z;
    	 Pair(int x,int y,int z){
    		 this.x=x;
    		 this.y=y;
    		 this.z=z;
    	 }
		@Override
//		public int compareTo(Pair o) {
//			if(this.x>o.x)
//				return 1;
//			else if(this.x<o.x)
//				return -1;
//			else {
//				if(this.y>o.y)
//					return 1;
//				else if(this.y<o.y)
//					return -1;
//				else
//					return 0;
//			}
//		}

		public int compareTo(Pair o) {
			int p=this.x-this.y;
			int q=o.x-o.y;
		if(p>q)
			return 1;
		else if(p<q)
			return -1;

				return 0;

	}
     }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;
public class B{
	static int[][] hor;
	static int[][] ver;
	static int n;
	static int m;
	static int k;
	static long[][][] dp;

	static long dist(int row, int col)
	{
		if(k%2==1)return Integer.MAX_VALUE;
		return 2*make(row,col,k/2);
	}

	static long make(int row, int col, int moves)
	{
		if(moves == 0)
		{
			return 0;
		}

		if(dp[row][col][moves]!=-1)return dp[row][col][moves];

		long ans = Long.MAX_VALUE;

		if(col-1>=0)
		{
			ans = Math.min(ans, hor[row][col-1]+make(row,col-1,moves-1));
		}
		if(col+1<m)
		{
			ans = Math.min(ans, hor[row][col]+make(row,col+1,moves-1));
		}
		if(row-1>=0)
		{
			ans = Math.min(ans, ver[row-1][col]+make(row-1,col,moves-1));
		}
		if(row+1<n)
		{
			ans = Math.min(ans, ver[row][col]+make(row+1,col,moves-1));
		}
		dp[row][col][moves] = ans;
		return ans;
	}

	public static void main(String[] args)
	{
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		n = fs.nextInt(); m = fs.nextInt(); k = fs.nextInt();
		hor = new int[n][m]; ver = new int[n][m];
		dp = new long[505][505][24];
		for(int i=0;i<505;i++)for(int j=0;j<505;j++)for(int k=0;k<24;k++)dp[i][j][k] = -1;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m-1;j++)
			{
				int a = fs.nextInt();
				hor[i][j] = a;
			}
		}

		for(int row=0;row<n-1;row++)
		{
			for(int col =0;col<m;col++)
			{
				int a = fs.nextInt();
				ver[row][col] = a;
			}
		}

		for(int row=0;row<n;row++)
		{
			for(int col=0;col<m;col++)
			{
				long d = dist(row,col);
				if(d<Integer.MAX_VALUE)
				{
					out.print(d+" ");
				}
				else out.print("-1 ");
			}
			out.println();
		}
		out.close();
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static int[] sort(int[] arr)
	{
		List<Integer> temp = new ArrayList();
		for(int i:arr)temp.add(i);
		Collections.sort(temp);
		int start = 0;
		for(int i:temp)arr[start++]=i;
		return arr;
	}
}


import java.util.*;
import java.io.*;
import java.math.*;

/**
 *
 * @Har_Har_Mahadev
 */

public class D {

	private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;
	private static int N = 0;
	private static long[][][] dp;
	private static long[][] ff;
	private static long[][] ss;

	public static void process() throws IOException {

		int n = sc.nextInt(),m = sc.nextInt(),k = sc.nextInt();

		ff = new long[n][m];
		ss = new long[n][m];
		for(int i = 0; i<n; i++) {
			for(int j = 0; j<m-1; j++) {
				ff[i][j] = sc.nextLong();
			}
		}
		for(int i = 0; i<n-1; i++) {
			for(int j = 0; j<m; j++) {
				ss[i][j] = sc.nextLong();
			}
		}

		if(k%2 == 1) {
			for(int i = 0; i<n; i++) {
				for(int j = 0; j<m; j++)System.out.print(-1+" ");
				System.out.println();
			}
			return;
		}

		dp = new long[n+1][m+1][11];
		for(int i = 0; i<=n; i++) {
			for(int j = 0; j<=m; j++)Arrays.fill(dp[i][j], -1);
		}
		for(int i = 0; i<=n; i++) {
			for(int j = 0; j<=m; j++) {
				dp[i][j][0] = 0;
			}
		}

		k/=2;
		long ans[][] = new long[n][m];
		for(int i = 0; i<n; i++) {
			for(int j = 0; j<m; j++) {
				ans[i][j] = solve(i,j,k,n,m)*2L;
			}
		}
		for(int i = 0; i<n; i++) {
			for(int j = 0; j<m; j++)print(ans[i][j]+" ");
			println();
		}
	}

	private static long solve(int i, int j, int k, int n, int m) {
		if(dp[i][j][k] != -1)return dp[i][j][k];
		long ans = Long.MAX_VALUE;
		if(i+1<n) {
			ans = min(ans,ss[i][j] + solve(i+1, j, k-1, n, m));
		}
		if(i-1>=0) {
			ans = min(ans,ss[i-1][j] + solve(i-1, j, k-1, n, m));
		}
		if(j+1<m) {
			ans = min(ans,ff[i][j] + solve(i, j+1, k-1, n, m));
		}
		if(j-1>=0) {
			ans = min(ans,ff[i][j-1] + solve(i, j-1, k-1, n, m));
		}

		return dp[i][j][k] = ans;
	}

	//=============================================================================
	//--------------------------The End---------------------------------
	//=============================================================================

	static FastScanner sc;
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		boolean oj = true;
		if (oj) {
			sc = new FastScanner();
			out = new PrintWriter(System.out);
		} else {
			sc = new FastScanner(100);
			out = new PrintWriter("output.txt");
		}
		int t = 1;
//		t = sc.nextInt();
		while (t-- > 0) {
			process();
		}
		out.flush();
		out.close();
	}

	static class Pair implements Comparable<Pair> {
		int x, y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(Pair o) {
			return Integer.compare(this.x, o.x);
		}

		//		 @Override
		//		    public boolean equals(Object o) {
		//		        if (this == o) return true;
		//		        if (!(o instanceof Pair)) return false;
		//		        Pair key = (Pair) o;
		//		        return x == key.x && y == key.y;
		//		    }
		//
		//		    @Override
		//		    public int hashCode() {
		//		        int result = x;
		//		        result = 31 * result + y;
		//		        return result;
		//		    }
	}

	/////////////////////////////////////////////////////////////////////////////////////////////////////////

	static void println(Object o) {
		out.println(o);
	}

	static void println() {
		out.println();
	}

	static void print(Object o) {
		out.print(o);
	}

	static void pflush(Object o) {
		out.println(o);
		out.flush();
	}

	static int ceil(int x, int y) {
		return (x % y == 0 ? x / y : (x / y + 1));
	}

	static long ceil(long x, long y) {
		return (x % y == 0 ? x / y : (x / y + 1));
	}

	static int max(int x, int y) {
		return Math.max(x, y);
	}

	static int min(int x, int y) {
		return Math.min(x, y);
	}

	static int abs(int x) {
		return Math.abs(x);
	}

	static long abs(long x) {
		return Math.abs(x);
	}

	static long sqrt(long z) {
		long sqz = (long) Math.sqrt(z);
		while (sqz * 1L * sqz < z) {
			sqz++;
		}
		while (sqz * 1L * sqz > z) {
			sqz--;
		}
		return sqz;
	}

	static int log2(int N) {
		int result = (int) (Math.log(N) / Math.log(2));
		return result;
	}

	static long max(long x, long y) {
		return Math.max(x, y);
	}

	static long min(long x, long y) {
		return Math.min(x, y);
	}

	public static int gcd(int a, int b) {
		BigInteger b1 = BigInteger.valueOf(a);
		BigInteger b2 = BigInteger.valueOf(b);
		BigInteger gcd = b1.gcd(b2);
		return gcd.intValue();
	}

	public static long gcd(long a, long b) {
		BigInteger b1 = BigInteger.valueOf(a);
		BigInteger b2 = BigInteger.valueOf(b);
		BigInteger gcd = b1.gcd(b2);
		return gcd.longValue();
	}

	public static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static int lcm(int a, int b) {
		return (a * b) / gcd(a, b);
	}

	public static int lower_bound(int[] arr, int x) {
		int low = 0, high = arr.length, mid = -1;

		while (low < high) {
			mid = (low + high) / 2;

			if (arr[mid] >= x)
				high = mid;
			else
				low = mid + 1;
		}

		return low;
	}

	public static int upper_bound(int[] arr, int x) {
		int low = 0, high = arr.length, mid = -1;

		while (low < high) {
			mid = (low + high) / 2;

			if (arr[mid] > x)
				high = mid;
			else
				low = mid + 1;
		}

		return low;
	}

	/////////////////////////////////////////////////////////////////////////////////////////////////////////

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner() throws FileNotFoundException {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		FastScanner(int a) throws FileNotFoundException {
			br = new BufferedReader(new FileReader("input.txt"));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readArray(int n) throws IOException {
			int[] A = new int[n];
			for (int i = 0; i != n; i++) {
				A[i] = sc.nextInt();
			}
			return A;
		}

		long[] readArrayLong(int n) throws IOException {
			long[] A = new long[n];
			for (int i = 0; i != n; i++) {
				A[i] = sc.nextLong();
			}
			return A;
		}
	}

	static void ruffleSort(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
		Arrays.sort(a);
	}

	static void ruffleSort(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
		Arrays.sort(a);
	}
}


import java.util.*;

import java.io.*;

public class D {

    static int mod = (int) (1e9+7);
    static InputReader in;
    static PrintWriter out;

    static void solve()
    {

        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        int t = 1;

        while(t-- > 0) {
        	int n = in.nextInt();
        	int m = in.nextInt();
        	int K = in.nextInt();

        	long[][] x = new long[n][];

        	for(int i = 0; i < n; i++) {
        		x[i] = in.nextLongArray(m - 1);
        	}

        	long[][] y = new long[n - 1][];
        	for(int i = 0; i < n - 1; i++) {
        		y[i] = in.nextLongArray(m);
        	}

        	if(K % 2 != 0) {
            	for(int i = 0; i < n; i++) {
            		for(int j = 0; j < m; j++) {
            			out.print("-1 ");
            		}
            		out.println();
            	}
        		continue;
        	}
        	K /= 2;

        	long[][][] dp = new long[K + 1][n][m];

        	for(int i = 0; i < n; i++) {
        		for(int j = 0; j < m; j++) {
        			for(int k = 1; k <= K; k++) {
        				dp[k][i][j] = Integer.MAX_VALUE;
        			}
        		}
        	}

        	for(int k = 1; k <= K; k++) {
	        	for(int i = 0; i < n; i++) {
	        		for(int j = 0; j < m; j++) {
	        			if(i + 1 < n) {
	        				dp[k][i][j] = Math.min(dp[k][i][j], dp[k - 1][i + 1][j] + 2 * y[i][j]);
	        			}
	        			if(i - 1 >= 0) {
	        				dp[k][i][j] = Math.min(dp[k][i][j], dp[k - 1][i - 1][j] + 2 * y[i - 1][j]);
	        			}
	        			if(j + 1 < m) {
	        				dp[k][i][j] = Math.min(dp[k][i][j], dp[k - 1][i][j + 1] + 2 * x[i][j]);
	        			}
	        			if(j - 1 >= 0) {
	        				dp[k][i][j] = Math.min(dp[k][i][j], dp[k - 1][i][j - 1] + 2 * x[i][j - 1]);
	        			}
	        		}
	        	}
        	}

        	for(int i = 0; i < n; i++) {
        		for(int j = 0; j < m; j++) {
        			out.print(dp[K][i][j] + " ");
        		}
        		out.println();
        	}

        }

        out.close();

    }

    public static void main(String[] args) {
        new Thread(null ,new Runnable(){
            public void run()
            {
                try{
                    solve();
                } catch(Exception e){
                    e.printStackTrace();
                }
            }
        },"1",1<<26).start();
    }

    static int[][] graph(int from[], int to[], int n)
    {
        int g[][] = new int[n][];
        int cnt[] = new int[n];
        for (int i = 0; i < from.length; i++) {
            cnt[from[i]]++;
            cnt[to[i]]++;
        }
        for (int i = 0; i < n; i++) {
            g[i] = new int[cnt[i]];
        }
        Arrays.fill(cnt, 0);
        for (int i = 0; i < from.length; i++) {
            g[from[i]][cnt[from[i]]++] = to[i];
            g[to[i]][cnt[to[i]]++] = from[i];
        }
        return g;
    }

    static class Pair implements Comparable<Pair>{

        int x,y,z;

		Pair (int x,int y,int z){
			this.x=x;
			this.y=y;
			this.z=z;
		}

		public int compareTo(Pair o) {
			if (this.x == o.x)
				return Integer.compare(this.y,o.y);
			return Integer.compare(this.x,o.x);
			//return 0;
		}

        public boolean equals(Object o) {
            if (o instanceof Pair) {
                Pair p = (Pair)o;
                return p.x == x && p.y == y;
            }
            return false;
        }
        public int hashCode() {
            return new Integer(x).hashCode() * 31 + new Integer(y).hashCode();
        }

        @Override
        public String toString() {
        	return x + " " + y;
        }

    }

    static String rev(String s) {
        StringBuilder sb = new StringBuilder(s);
        sb.reverse();
        return sb.toString();
    }

    static long gcd(long x, long y) {
        if (y == 0) {
            return x;
        } else {
            return gcd(y, x % y);
        }
    }

    static int gcd(int x, int y) {
        if (y == 0) {
            return x;
        } else {
            return gcd(y, x % y);
        }
    }

    static int abs(int a, int b) {
        return (int) Math.abs(a - b);
    }

    static long abs(long a, long b) {
        return (long) Math.abs(a - b);
    }

    static int max(int a, int b) {
        if (a > b) {
            return a;
        } else {
            return b;
        }
    }

    static int min(int a, int b) {
        if (a > b) {
            return b;
        } else {
            return a;
        }
    }

    static long max(long a, long b) {
        if (a > b) {
            return a;
        } else {
            return b;
        }
    }

    static long min(long a, long b) {
        if (a > b) {
            return b;
        } else {
            return a;
        }
    }

    static long pow(long n, long p, long m) {
        long result = 1;
        if (p == 0) {
            return 1;
        }
        while (p != 0) {
            if (p % 2 == 1) {
                result *= n;
            }
            if (result >= m) {
                result %= m;
            }
            p >>= 1;
            n *= n;
            if (n >= m) {
                n %= m;
            }
        }
        return result;
    }

    static long pow(long n, long p) {
        long result = 1;
        if (p == 0) {
            return 1;
        }
        if (p == 1) {
            return n;
        }
        while (p != 0) {
            if (p % 2 == 1) {
                result *= n;
            }
            p >>= 1;
            n *= n;
        }
        return result;
    }

    static void debug(Object... o) {
            System.out.println(Arrays.deepToString(o));
    }

    static class InputReader
    {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
                this.stream = stream;
        }

        public int snext()
        {
                if (snumChars == -1)
                        throw new InputMismatchException();
                if (curChar >= snumChars)
                {
                        curChar = 0;
                        try
                        {
                                snumChars = stream.read(buf);
                        } catch (IOException e)
                        {
                                throw new InputMismatchException();
                        }
                        if (snumChars <= 0)
                                return -1;
                }
                return buf[curChar++];
        }

        public int nextInt()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                int res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public long nextLong()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                long res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public int[] nextIntArray(int n)
        {
                int a[] = new int[n];
                for (int i = 0; i < n; i++)
                {
                        a[i] = nextInt();
                }
                return a;
        }

        public long[] nextLongArray(int n)
        {
                long a[] = new long[n];
                for (int i = 0; i < n; i++)
                {
                        a[i] = nextLong();
                }
                return a;
        }

        public String readString()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
        }

        public String nextLine()
        {
                int c = snext();
                while (isSpaceChar(c))
                        c = snext();
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
                if (filter != null)
                        return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c)
        {
                return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter
        {
                public boolean isSpaceChar(int ch);
        }

    }
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[])
    {
        FastReader input=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int T=1;
        while(T-->0)
        {
            int n=input.nextInt();
            int m=input.nextInt();
            int k=input.nextInt();
            int arr1[][]=new int[n+1][m];
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<m;j++)
                {
                    arr1[i][j]=input.nextInt();
                }
            }
            int arr2[][]=new int[n][m+1];
            for(int i=1;i<n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    arr2[i][j]=input.nextInt();
                }
            }
            if(k%2==0)
            {
                int dp[][][]=new int[n+1][m+1][k+1];
                for(int l=2;l<=k;l+=2)
                {
                    for(int i=1;i<=n;i++)
                    {
                        for(int j=1;j<=m;j++)
                        {
                            int min=Integer.MAX_VALUE;
                            if(j+1<=m)
                            {
                                min=Math.min(min,dp[i][j+1][l-2]+2*arr1[i][j]);
                            }
                            if(i+1<=n)
                            {
                                min=Math.min(min,dp[i+1][j][l-2]+2*arr2[i][j]);
                            }
                            if(j-1>=1)
                            {
                                min=Math.min(min,dp[i][j-1][l-2]+2*arr1[i][j-1]);
                            }
                            if(i-1>=1)
                            {
                                min=Math.min(min,dp[i-1][j][l-2]+2*arr2[i-1][j]);
                            }
                            dp[i][j][l]=min;
                        }
                    }
                }
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=m;j++)
                    {
                        out.print(dp[i][j][k]+" ");
                    }
                    out.println();
                }
            }
            else
            {
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=m;j++)
                    {
                        out.print(-1+" ");
                    }
                    out.println();
                }
            }
        }
        out.close();
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt()
        {
            return Integer.parseInt(next());
        }
        long nextLong()
        {
            return Long.parseLong(next());
        }
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
        String nextLine()
        {
            String str="";
            try
            {
                str=br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

// Created by @thesupremeone on 23/04/21
public class ExplorerSpace {
    int[][] horizontal, vertical;
    int n, m;
    long[][][] dp;
    int large = Integer.MAX_VALUE;

    boolean isValid(int i, int j){
        return i>=0 && j>=0 && i<n && j<m;
    }

    long getMin(int i, int j, int k){
        if(k==0)
            return 0;
        if(dp[i][j][k]!=-1)
            return dp[i][j][k];
        long ans = large;
        for (int a = 0; a < 2; a++) {
            for (int d = 0; d < 2; d++) {
                int dx = a==0 ? (d==0 ? +1 : -1) : 0;
                int dy = a==1 ? (d==0 ? +1 : -1) : 0;
                int x = i+dx;
                int y = j+dy;
                if(isValid(x, y)){
                    if(dx==0){
                        ans = Math.min(horizontal[i][Math.min(j, y)]+getMin(x, y, k-1), ans);
                    }else {
                        ans = Math.min(vertical[Math.min(i, x)][j]+getMin(x, y, k-1), ans);
                    }
                }
            }
        }
        dp[i][j][k] = ans;
        return ans;
    }

    void solve() throws IOException {
        n = getInt();
        m = getInt();
        dp = new long[n+1][m+1][11];
        for (int i = 0; i < n+1; i++) {
            for (int j = 0; j < m+1; j++) {
                for (int k = 0; k < 11; k++) {
                    dp[i][j][k] = -1;
                }
            }
        }
        int k = getInt();
        horizontal = new int[n][m-1];
        vertical = new int[n-1][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m - 1; j++) {
                horizontal[i][j] = getInt();
            }
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < m; j++) {
                vertical[i][j] = getInt();
            }
        }
        if(k%2!=0){
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    print("-1 ");
                }
                println("");
            }
        }else {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    long ans = 2*getMin(i, j, k/2);
                    print(ans+" ");
                }
                println("");
            }
        }
    }

    public static void main(String[] args) throws Exception {
        if (isOnlineJudge()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            new ExplorerSpace().solve();
            out.flush();
        } else {
            Thread judge = new Thread();
            in = new BufferedReader(new FileReader("input.txt"));
            out = new BufferedWriter(new FileWriter("output.txt"));
            judge.start();
            new ExplorerSpace().solve();
            out.flush();
            judge.suspend();
        }
    }
    static boolean isOnlineJudge(){
        try {
            return System.getProperty("ONLINE_JUDGE")!=null
                    || System.getProperty("LOCAL")==null;
        }catch (Exception e){
            return true;
        }
    }
    // Fast Input & Output
    static BufferedReader in;
    static StringTokenizer st;
    static BufferedWriter out;
    static String getLine() throws IOException{
        return in.readLine();
    }
    static String getToken() throws IOException{
        if(st==null || !st.hasMoreTokens())
            st = new StringTokenizer(getLine());
        return st.nextToken();
    }
    static int getInt() throws IOException {
        return Integer.parseInt(getToken());
    }
    static long getLong() throws IOException {
        return Long.parseLong(getToken());
    }
    static void print(Object s) throws IOException{
        out.write(String.valueOf(s));
    }
    static void println(Object s) throws IOException{
        out.write(String.valueOf(s));
        out.newLine();
    }
}


// package com.company.codeforces;

import java.util.*;

public class  Solution {
   static int n,m,h[][],v[][];
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);

            n=input.nextInt();
            m=input.nextInt();
           int k=input.nextInt();
           h=new int[n][m-1];
            for (int i = 0; i <n ; i++) {
                for (int j = 0; j <m-1 ; j++) {
                    h[i][j]=input.nextInt();
                }
            }
            v=new int[n][m];
            for (int i = 0; i <n-1 ; i++) {
                for (int j = 0; j <m ; j++) {
                    v[i][j]=input.nextInt();
                }
            }
            int ans[][]=new int[n][m];
           dp=new int[501][501][11];
        for (int aa[]:ans
             ) { Arrays.fill(aa,-1);

        }
        if (k%2==0) {

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ans[i][j] = dfs(i, j, k / 2) * 2;
                }

            }
        }
        for (int i = 0; i <n ; i++) {
            for (int j = 0; j <m ; j++) {
                System.out.print(ans[i][j]+" ");
            }
            System.out.println();

        }

    }
    static int dp[][][];

    private static int dfs(int i, int j, int k) {
        if (k==0) return 0;
        if (dp[i][j][k]!=0){
//            System.out.println("hit");
            return dp[i][j][k];
        }
        //left
        int ans=Integer.MAX_VALUE;
        if (j-1>=0)
         ans=dfs(i, j-1, k-1)+h[i][j-1];
        if (i<n-1)
        ans=Math.min(ans,dfs(i+1, j, k-1)+v[i][j]);
        if (i>0)
        ans=Math.min(ans,dfs(i-1, j, k-1)+v[i-1][j]);
        if (j<m-1)
        ans=Math.min(ans,dfs(i, j+1, k-1)+h[i][j]);

        return dp[i][j][k]= ans;

    }

}


//package Codeforces.Round718Div1_2;

import java.io.*;
import java.util.*;

public class D {
    static boolean isValid(int n, int m, int i, int j){
        return 0<=i && i<n && 0<=j && j<m;
    }
    public static void main(String[] args) throws IOException {
        Soumit sc = new Soumit();

        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        StringBuilder sb = new StringBuilder();
        if(k%2==1){
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    sb.append("-1 ");
                }
                sb.append("\n");
            }
            System.out.println(sb);
            System.exit(0);
        }

        k/=2;

        long[][] horizontaledge = new long[n][m-1];
        long[][] verticaledge = new long[n-1][m];
        for(int i=0;i<n;i++)
            horizontaledge[i] = sc.nextLongArray(m-1);
        for(int i=0;i<n-1;i++)
            verticaledge[i] = sc.nextLongArray(m);

        long[][][] dp = new long[11][n][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                dp[0][i][j] = 0;
            }
        }
        for(int i=1;i<=k;i++){
            for(int j1=0;j1<n;j1++){
                for(int j2=0;j2<m;j2++){
                    long min = Long.MAX_VALUE/2000;
                    //for up
                    if(isValid(n, m, j1-1, j2)){
                        min = Math.min(dp[i-1][j1-1][j2]+verticaledge[j1-1][j2], min);
                    }

                    //for down
                    if(isValid(n, m, j1+1, j2)){
                        min = Math.min(min, dp[i-1][j1+1][j2]+verticaledge[j1][j2]);
                    }

                    //for left
                    if(isValid(n, m, j1, j2-1)){
                        min = Math.min(min, dp[i-1][j1][j2-1]+horizontaledge[j1][j2-1]);
                    }

                    //for right
                    if(isValid(n, m, j1, j2+1)){
                        min = Math.min(min, dp[i-1][j1][j2+1]+horizontaledge[j1][j2]);
                    }

                    dp[i][j1][j2] = min;
                }
            }
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                sb.append(dp[k][i][j]*2).append(" ");
            }
            sb.append("\n");
        }

        System.out.println(sb);

        sc.close();
    }

    static class Soumit {
        final private int BUFFER_SIZE = 1 << 18;
        final private DataInputStream din;
        final private byte[] buffer;
        private PrintWriter pw;
        private int bufferPointer, bytesRead;
        StringTokenizer st;

        public Soumit() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Soumit(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public void streamOutput(String file) throws IOException {
            FileWriter fw = new FileWriter(file);
            BufferedWriter bw = new BufferedWriter(fw);
            pw = new PrintWriter(bw);
        }

        public void println(String a) {
            pw.println(a);
        }

        public void print(String a) {
            pw.print(a);
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[3000064]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public void sort(int[] arr) {
            ArrayList<Integer> arlist = new ArrayList<>();
            for (int i : arr)
                arlist.add(i);

            Collections.sort(arlist);
            for (int i = 0; i < arr.length; i++)
                arr[i] = arlist.get(i);
        }

        public void sort(long[] arr) {
            ArrayList<Long> arlist = new ArrayList<>();
            for (long i : arr)
                arlist.add(i);

            Collections.sort(arlist);
            for (int i = 0; i < arr.length; i++)
                arr[i] = arlist.get(i);
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }

            return arr;
        }

        public long[] nextLongArray(int n) throws IOException {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }

            return arr;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }

            return arr;
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            /*if (din == null)
                return;*/
            if (din != null) din.close();
            if (pw != null) pw.close();
        }
    }
}


//Template with FastScanner

// jzzhao

import java.util.*;
import java.io.*;

public class Solution {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        //int tc = sc.ni();
        int tc = 1;
        for (int rep = 0; rep < tc; rep++) {
            solve(sc,pw);
            //pw.println(solve(sc,pw));

        }

        pw.close();
    }
    /*

    FS Methods:

    - next(): next element in string
    - nextLine(): nextline in string
    - ni(): next Integer
    - nd(): next Double
    - nl(): next Long
    - intArray(n):
    - longArray(n):
    - to2di(m,n):
    - to2dl(m,n):

    */

    public static void solve(FastScanner sc, PrintWriter pw) {

        int n = sc.ni();
        int m = sc.ni();
        int k = sc.ni();

        int[][] arr = sc.to2di(n,m-1);
        int[][] arr2 = sc.to2di(n-1,m);

        if(k%2==1){
            String s ="";
            for(int j = 0;j<m;j++){
                s+="-1";
                if(j!=m-1){
                    s+=" ";
                }
            }
            for(int i = 0;i<n;i++){
                pw.println(s);
            }
            return;
        }

        Integer[][][] dp = new Integer[n][m][k+1];

        // edge info
        // for(int i= 0;i<n;i++){
        //     for(int j = 0;j<m-1;j++){

        //         int l = i*1000+j;
        //         int r = i*1000+j+1;
        //         String cur = l+" "+r;
        //         String cur2 = r+" "+l;
        //         map.put(cur,arr[i][j]);
        //         map.put(cur2,arr[i][j]);

        //     }
        // }

        // for(int i= 0;i<n-1;i++){
        //     for(int j = 0;j<m;j++){

        //         int l = i*1000+j;
        //         int r = (i+1)*1000+j;
        //         String cur = l+" "+r;
        //         String cur2 = r+" "+l;
        //         map.put(cur,arr2[i][j]);
        //         map.put(cur2,arr2[i][j]);

        //     }
        // }

        //dp fill

        for(int i= 0;i<n;i++){
            for(int j = 0;j<m;j++){

                fill(dp,i,j,k,n,m,arr,arr2);

            }
        }

        for(int i= 0;i<n;i++){
            String s = "";
            for(int j = 0;j<m;j++){

                s+=dp[i][j][k];
                if(j!=m-1){
                    s+=" ";
                }

            }
            pw.println(s);
        }

    }

    public static int fill(Integer[][][] dp, int x, int y, int k, int n,int m,int[][] arr, int[][] arr2){

        if(dp[x][y][k]!=null){
            return dp[x][y][k];
        }

        if(k==0){
            dp[x][y][k]= 0;
            return 0;
        }

        int min = Integer.MAX_VALUE;

        if(x>0){

            int curVal = 2*arr2[x-1][y]+fill(dp,x-1,y,k-2,n,m,arr,arr2);
            min = Math.min(min,curVal);
        }

        if(y>0){

            int curVal = 2*arr[x][y-1]+fill(dp,x,y-1,k-2,n,m,arr,arr2);
            min = Math.min(min,curVal);
        }

        if(x<n-1){

            int curVal = 2*arr2[x][y]+fill(dp,x+1,y,k-2,n,m,arr,arr2);
            min = Math.min(min,curVal);
        }

        if(y<m-1){

            int curVal = 2*arr[x][y]+fill(dp,x,y+1,k-2,n,m,arr,arr2);
            min = Math.min(min,curVal);
        }

        dp[x][y][k]=min;
        return min;

    }

    /*
        - The following are helping method so pls do not do anything to them.

    */

    // public static int[][] to2d(Scanner scanner, int m, int n){
    //     int[][] ans = new int[m][n];
    //     for(int i = 0;i<m;i++){
    //         String[] r = scanner.nextLine().split("[ ]");
    //         for(int j = 0;j<n;j++){
    //             ans[i][j] = stoi(r[j]);
    //         }
    //     }
    //     return ans;
    // }

    // public static int[] toArray(Scanner scanner, int m){
    //     int[] ans = new int[m];
    //     String[] r = scanner.nextLine().split("[ ]");
    //     for(int i = 0;i<m;i++){
    //         ans[i] = stoi(r[i]);
    //     }

    //     return ans;
    // }

    public static void printArr(PrintWriter pw,int[] a){
        for(int i = 0;i<a.length;i++){
            pw.print(a[i]);
            if(i!=a.length-1){
                pw.print(" ");
            }
        }
        pw.println();
    }

    public static void print2d(PrintWriter pw,int[][] a){
        for(int j=0;j<a.length;j++){
            for(int i = 0;i<a[j].length;i++){
                pw.print(a[j][i]);
                if(i!=a[j].length-1){
                    pw.print(" ");
                }
            }
            pw.println(" ");
        }
        pw.println();
    }

    public static int stoi(String s){
        return Integer.parseInt(s);
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in), 32768);
        st = null;
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();

            }
        }
        return st.nextToken();
    }

    int ni() {
        return Integer.parseInt(next());
    }

    int[] intArray(int N) {
        int[] ret = new int[N];
        for (int i = 0; i < N; i++)
            ret[i] = ni();
        return ret;
    }

    int[][] to2di(int m, int n){
        int[][] ans = new int[m][n];
        for(int i = 0;i<m;i++){
            String[] r = nextLine().split("[ ]");
            for(int j = 0;j<n;j++){
                ans[i][j] = Integer.parseInt(r[j]);
            }
        }
        return ans;
    }

    long[][] to2dl(int m, int n){
        long[][] ans = new long[m][n];
        for(int i = 0;i<m;i++){
            String[] r = nextLine().split("[ ]");
            for(int j = 0;j<n;j++){
                ans[i][j] = Long.parseLong(r[j]);
            }
        }
        return ans;
    }

    long nl() {
        return Long.parseLong(next());
    }

    long[] longArray(int N) {
        long[] ret = new long[N];
        for (int i = 0; i < N; i++)
            ret[i] = nl();
        return ret;
    }

    double nd() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}


import java.io.*;
import java.util.*;

public class Main{
	static int[][][]memo;
	static int inf=(int)1e9;
	static int n,m,down[][],right[][];
	static int dp(int i,int j,int k) {
		if(k<=0)return 0;
		if(memo[i][j][k]!=-1)return memo[i][j][k];
		int ans=inf;
		if(i+1<n) {
			ans=Math.min(ans, down[i][j]+dp(i+1, j, k-1));
		}

		if(i-1>=0) {
			ans=Math.min(ans, down[i-1][j]+dp(i-1, j, k-1));
		}

		if(j+1<m) {
			ans=Math.min(ans, right[i][j]+dp(i, j+1, k-1));
		}

		if(j-1>=0) {
			ans=Math.min(ans, right[i][j-1]+dp(i, j-1, k-1));
		}
		return memo[i][j][k]=ans;
	}
	static void main() throws Exception{
		n=sc.nextInt();m=sc.nextInt();int k=sc.nextInt();
		if((k&1)==1) {
			for(int i=0;i<n;i++) {
				for(int j=0;j<m;j++) {
					pw.print((-1)+" ");
				}
				pw.println();
			}
			return;
		}
		k>>=1;
		right=new int[n][];
		down=new int[n-1][];
		for(int i=0;i<n;i++) {
			right[i]=sc.intArr(m-1);
		}
		for(int i=0;i<n-1;i++) {
			down[i]=sc.intArr(m);
		}
		memo = new int[n][m][k+1];
		int inf=(int)1e9;
		for(int i=0;i<=k;i++) {
			for(int j=0;j<n;j++) {
				for(int o=0;o<m;o++) {
					memo[j][o][i]=-1;
				}
			}
		}

		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				pw.print((dp(i, j, k)<<1)+" ");
			}
			pw.println();
		}
    }
    public static void main(String[] args) throws Exception{
    	sc=new MScanner(System.in);
    	pw = new PrintWriter(System.out);
        int tc=1;
//        tc=sc.nextInt();
        for(int i=1;i<=tc;i++) {
//            pw.printf("Case #%d:", i);
            main();
        }
        pw.flush();
    }
    static PrintWriter pw;
    static MScanner sc;
    static class MScanner {
        StringTokenizer st;
        BufferedReader br;
        public MScanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public MScanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public int[] intArr(int n) throws IOException {
            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
            return in;
        }
        public long[] longArr(int n) throws IOException {
            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            return in;
        }
        public int[] intSortedArr(int n) throws IOException {
            int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
            shuffle(in);
            Arrays.sort(in);
            return in;
        }
        public long[] longSortedArr(int n) throws IOException {
            long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            shuffle(in);
            Arrays.sort(in);
            return in;
        }
        public Integer[] IntegerArr(int n) throws IOException {
            Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
            return in;
        }
        public Long[] LongArr(int n) throws IOException {
            Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
            return in;
        }
        public String nextLine() throws IOException {
            return br.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

    }
    static void sort(int[]in) {
    	shuffle(in);
        Arrays.sort(in);
    }
    static void sort(long[]in) {
    	shuffle(in);
        Arrays.sort(in);
    }
    static void shuffle(int[]in) {
        for(int i=0;i<in.length;i++) {
            int idx=(int)(Math.random()*in.length);
            int tmp=in[i];
            in[i]=in[idx];
            in[idx]=tmp;
        }
    }
    static void shuffle(long[]in) {
        for(int i=0;i<in.length;i++) {
            int idx=(int)(Math.random()*in.length);
            long tmp=in[i];
            in[i]=in[idx];
            in[idx]=tmp;
        }
    }
}


import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
	static PrintWriter out;
	static Reader in;
	public static void main(String[] args) throws IOException {
		input_output();
		Main solver = new Main();
		solver.solve();
		out.close();
		out.flush();
	}

	static int INF = (int)1e9;
	static int MAXN = (int)4e5 + 5;
	static int MOD = (int)1e9+7;
	static int q, t, n, m, k;
	static double pi = Math.PI;

	void solve() throws IOException {
		n = in.nextInt();
		m = in.nextInt();
		k = in.nextInt();

		int[][] right = new int[n][m],
			    left = new int[n][m],
			    up = new int[n][m],
			    down = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m-1; j++) {
				right[i][j] = in.nextInt();
				left[i][j+1] = right[i][j];
			}
		}
		for (int i = 0; i < n-1; i++) {
			for (int j = 0; j < m; j++) {
				down[i][j] = in.nextInt();
				up[i+1][j] = down[i][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[n][m][k+1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				for (int kk = 1; kk <= k; kk++) {
					dp[i][j][kk] = INF;
				}
			}
		}

		for (int step = 2; step <= k; step+=2) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (i != 0) {
						dp[i][j][step] = Math.min(dp[i][j][step], dp[i-1][j][step-2]+up[i][j]*2);
					}
					if (i != n-1) {
						dp[i][j][step] = Math.min(dp[i][j][step], dp[i+1][j][step-2]+down[i][j]*2);
					}
					if (j != 0) {
						dp[i][j][step] = Math.min(dp[i][j][step], dp[i][j-1][step-2]+left[i][j]*2);
					}
					if (j != m-1) {
						dp[i][j][step] = Math.min(dp[i][j][step], dp[i][j+1][step-2]+right[i][j]*2);
					}
				}
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				out.print(dp[i][j][k]+" ");
			}
			out.println();
		}
	}

	static class Reader {
		private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public Reader() {
			this(System.in);
		}

		public Reader(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1) {
				throw new InputMismatchException();

			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}
	static void input_output() throws IOException {
		File f = new File("in.txt");
		if (f.exists() && !f.isDirectory()) {
			in = new Reader(new FileInputStream("in.txt"));
		} else in = new Reader();
		f = new File("out.txt");
		if (f.exists() && !f.isDirectory()) {
			out = new PrintWriter(new File("out.txt"));
		} else out = new PrintWriter(System.out);
	}
}


// Author : RegalBeast

import java.io.*;
import java.util.*;

public class Main {
  static final FastReader FR = new FastReader();
  static final PrintWriter PW = new PrintWriter(new OutputStreamWriter(System.out));

  public static void main(String[] args) {
    StringBuilder solution = new StringBuilder();
    int rows = FR.nextInt();
    int cols = FR.nextInt();
    int moves = FR.nextInt();

    List<List<Integer>> horizontalEdgeWeights = new ArrayList<List<Integer>>(rows);
    for (int r = 0; r < rows; r++) {
      horizontalEdgeWeights.add(new ArrayList<Integer>(cols-1));

      for (int c = 0; c < cols - 1; c++) {
        horizontalEdgeWeights.get(r).add(FR.nextInt());
      }
    }

    List<List<Integer>> verticalEdgeWeights = new ArrayList<List<Integer>>(rows-1);
    for (int r = 0; r < rows - 1; r++) {
      verticalEdgeWeights.add(new ArrayList<Integer>(cols));

      for (int c = 0; c < cols; c++) {
        verticalEdgeWeights.get(r).add(FR.nextInt());
      }
    }

    List<List<Integer>> result = getResult(rows, cols, moves, horizontalEdgeWeights, verticalEdgeWeights);
    for (int r = 0; r < rows; r++) {
      for (int c = 0; c < cols; c++) {
        int value = (result != null ? result.get(r).get(c) : -1);
        solution.append(value + " ");
      }
      solution.append("\n");
    }

		PW.print(solution.toString());
    PW.close();
  }

  static List<List<Integer>> getResult(int rows, int cols, int moves, List<List<Integer>> horizontalEdgeWeights, List<List<Integer>> verticalEdgeWeights) {
    if ((moves & 1) == 1) {
      return null;
    }

    int mid = moves >> 1;
    List<List<List<Integer>>> minForDistance = new ArrayList<List<List<Integer>>>(rows);
    for (int r = 0; r < rows; r++) {
      minForDistance.add(new ArrayList<List<Integer>>(cols));

      for (int c = 0; c < cols; c++) {
        minForDistance.get(r).add(new ArrayList<Integer>(Collections.nCopies(mid+1, Integer.MAX_VALUE)));
        minForDistance.get(r).get(c).set(0, 0);
      }
    }

    for (int m = 1; m <= mid; m++) {
      for (int r = 0; r < rows; r++) {
        for (int c = 0; c < cols; c++) {
          int minBoredom = minForDistance.get(r).get(c).get(m);

          if (r > 0) {
            if (minForDistance.get(r-1).get(c).get(m-1) < Integer.MAX_VALUE) {
              int candidateBoredom = minForDistance.get(r-1).get(c).get(m-1) + verticalEdgeWeights.get(r-1).get(c);
              minBoredom = Math.min(minBoredom, candidateBoredom);
            }
          }

          if (c > 0) {
            if (minForDistance.get(r).get(c-1).get(m-1) < Integer.MAX_VALUE) {
              int candidateBoredom = minForDistance.get(r).get(c-1).get(m-1) + horizontalEdgeWeights.get(r).get(c-1);
              minBoredom = Math.min(minBoredom, candidateBoredom);
            }
          }

          if (r + 1 < rows) {
            if (minForDistance.get(r+1).get(c).get(m-1) < Integer.MAX_VALUE) {
              int candidateBoredom = minForDistance.get(r+1).get(c).get(m-1) + verticalEdgeWeights.get(r).get(c);
              minBoredom = Math.min(minBoredom, candidateBoredom);
            }
          }

          if (c + 1 < cols) {
            if (minForDistance.get(r).get(c+1).get(m-1) < Integer.MAX_VALUE) {
              int candidateBoredom = minForDistance.get(r).get(c+1).get(m-1) + horizontalEdgeWeights.get(r).get(c);
              minBoredom = Math.min(minBoredom, candidateBoredom);
            }
          }

          minForDistance.get(r).get(c).set(m, minBoredom);
        }
      }
    }

    List<List<Integer>> result = new ArrayList<List<Integer>>(rows);
    for (int r = 0; r < rows; r++) {
      result.add(new ArrayList<Integer>(cols));

      for (int c = 0; c < cols; c++) {
        result.get(r).add(minForDistance.get(r).get(c).get(mid) << 1);
      }
    }

    return result;
  }

  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e)  {
        e.printStackTrace();
      }
      return str;
    }
  }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Set;

//@Japanese
/* PriorityQueueは拡張for文で出すとsortされてない順番で出てくる
 * longのbit演算は1L<<posに注意
 * JOIはMLEが厳しい。最悪shortを使う。
 * ArrayListはオートボクシングが遅いから、最悪自作listを使う
 */

/*略語
 * 2-to, 4-for, 8-from
 * -L -long(型), -P -素数Pを法とした余り
 * a,b -任意の引数, n,m -自然数, p -素数
 * pos -postition
 * abs -絶対値
 * min -minimum, max -maximum, ave -average
 * div -divide
 * pow -power(累乗)
 * ceil -ceiling(天井関数)
 * dt -data
 * ln -length
 * sc -scanner
 * INF -INFINITY
 * e97 -10E9+7=1000000007(prime often used)
 */

public class Main {
	public static void main(String[] args) throws Exception {

		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int h = sc.nexI();
		int w = sc.nexI();
		int k = sc.nexI();

		Graph grid = new Graph(h*w);

		for(int i=0; i<h; i++) {
			for(int j=1; j<w; j++) {
				long w1 = sc.nexL();
				grid.add2(getad(w, i, j-1), getad(w, i, j), w1);
			}
		}
		for(int i=1; i<h; i++) {
			for(int j=0; j<w; j++) {
				long w1 = sc.nexL();
				grid.add2(getad(w, i-1, j), getad(w, i, j), w1);
			}
		}

		if(k%2 != 0) {
			int[][] anss = new int[h][w];
			fill(anss,-1);
			for(int i=0; i<h; i++) {
				prtspas(anss[i]);
			}

			return;
		}
		if((h*w) == 1) {
			System.out.println(-1);
			return;
		}

		long[][] mincos = new long[(k/2)+1][h*w];
		fill(mincos[0],0L);

		for(int t=1; t<=(k/2); t++) {
			fill(mincos[t], INFL);
			for(int i=0; i<h; i++) {
				for(int j=0; j<w; j++) {
					int ad = getad(w, i, j);
					for(Edge e: grid.get(ad)) {
						mincos[t][ad] = min(mincos[t][ad], mincos[t-1][e.v2]+e.w);
					}
				}
			}
		}

		for(int i=0; i<(h*w); i++) {
			mincos[k/2][i]*=2L;
		}
		for(int i=0; i<h; i++) {
			prtspas(Arrays.copyOfRange(mincos[k/2], i*w, i*w + w));
		}

		out.flush();
		return;
	}

	public static int getad(int w, int i, int j) {
		return (i*w + j);
	}

	static class Graph { // @Japanese 重み付きグラフ
		private ArrayList<Node> dt = new ArrayList<>();

		Graph(int sz) {
			for (int i = 0; i < sz; i++) {
				Node node1 = new Node();
				dt.add(node1);
			}
		}

		public void add(int v8, int cnct2, long w) {
			dt.get(v8).add(new Edge(v8, cnct2, w));
		}

		public void add2(int v1, int v2, long w) {
			dt.get(v1).add(new Edge(v1, v2, w));
			dt.get(v2).add(new Edge(v2, v1, w));
		}

		public Set<Edge> get(int v) {
			return dt.get(v).getAll();
		}

		public int size() {
			return dt.size();
		}

		public int sizeOf(int v) {
			return dt.get(v).size();
		}

		public void clear() {
			for (int i = 0; i < dt.size(); i++)
				dt.get(i).clear();
		}

		public void clear(int v) {
			dt.get(v).clear();
		}

		private void add_v(Node v_new) {
			dt.add(v_new);
		}

		public void show2() {
			for (int i = 0; i < dt.size(); i++) {
				System.out.print(i + ":");
				for (Edge e : dt.get(i).getAll())
					e.show2();
				System.out.println();
			}
		}

		public static Graph make_Graph(int vn, int en, FastScanner sc) {
			Graph g = new Graph(vn);
			for (int i = 0; i < en; i++) {
				int s1 = sc.nexI() - 1;
				int g1 = sc.nexI() - 1;
				long w = sc.nexL();
				g.add2(s1, g1, w);
			}
			return g;
		}

		public static Graph make_tree(int vn, FastScanner sc) {
			Graph g = new Graph(vn);
			for (int i = 1; i < vn; i++) {
				int s1 = sc.nexI() - 1;
				int g1 = sc.nexI() - 1;
				long w = sc.nexL();
				g.add2(s1, g1, w);
			}
			return g;
		}

		private long[] dijkstra(int from) {
			PriorityQueue<Edge> dijk = new PriorityQueue<>(new CompEdge_float());
			long[] d8i = new long[this.dt.size()];
			fill(d8i, INFL);
			dijk.add(new Edge(from, 0L));

			while (!dijk.isEmpty()) {
				Edge dw = dijk.poll();
				if (d8i[dw.v2] > dw.w) {
					d8i[dw.v2] = dw.w;
					for (Edge e : this.get(dw.v2)) {
						long w2 = dw.w + e.w;
						if (d8i[e.v2] > w2)
							dijk.add(new Edge(e.v2, w2));
					}
				}
			}
			return d8i;
		}
	}

	static class Node { // 重みつきグラフの頂点
		private Set<Edge> next_vs = new HashSet<>();

		public void add(Edge cnct2) {
			next_vs.add(cnct2);
		}

		public Set<Edge> getAll() {
			return next_vs;
		}

		public int size() {
			return next_vs.size();
		}

		public void clear() {
			next_vs.clear();
		}

		public void addAll(Node list2add) {
			this.next_vs.addAll(list2add.next_vs);
		}
	}

	static class Edge { // @Japanese 重み着きのグラフの辺
		int from = -1, v2 = -1;
		long w;

		public Edge(int going2, long weight_route) {
			this.v2 = going2;
			this.w = weight_route;
		}

		public Edge(int come8, int going2, long weight_route) {
			this.from = come8;
			this.v2 = going2;
			this.w = weight_route;
		}

		public void show2() {
			System.out.println(this.from + "->" + this.v2 + " :w=" + this.w);
		}
	}

	static class CompEdge_float implements Comparator<Edge> {
		// 今は小さいのが前に出てくる
		public int compare(Edge a, Edge b) {
			if (a.w > b.w)
				return 1;
			else if (a.w < b.w)
				return -1;
			else
				return a.v2 - b.v2;
		}
	}

	private static final int INF = (int) 3e8;
	private static final long INFL = (long) 1e17;
	private static final int INTMAX = Integer.MAX_VALUE;
	private static final long LONGMAX = Long.MAX_VALUE;
	private static final long e97 = 1000000007L;
	private static final long e99 = 998244353L;
	private static final double PI = Math.PI;

	private static void assertion(boolean should_true) {
		// throw Error if should_true is not true @Japanese「断言」
		if (!should_true)
			throw new AssertionError();
	}

	private static int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	private static long abs(long a) {
		return (a >= 0L) ? a : -a;
	}

	private static double abs(double a) {
		return (a >= 0.0) ? a : -a;
	}

	private static int min(int a, int b) {
		return (a < b) ? a : b;
	}

	private static long min(long a, long b) {
		return (a < b) ? a : b;
	}

	private static double min(double a, double b) {
		return (a < b) ? a : b;
	}

	private static int max(int a, int b) {
		return (a > b) ? a : b;
	}

	private static long max(long a, long b) {
		return (a > b) ? a : b;
	}

	private static double max(double a, double b) {
		return (a > b) ? a : b;
	}

	private static int pow2(int num2pow) {
		if (num2pow > 4e4)
			throw new IllegalArgumentException("Input is to Large. Use Long.");
		return num2pow * num2pow;
	}

	private static long pow2(long num2pow) {
		if (num2pow > 1e8)
			throw new IllegalArgumentException("Input is to Large. Use PowP.");
		return num2pow * num2pow;
	}

	private static int pow(int num_powered, int index) {
		int ans = 1;
		for (int i = 0; i < index; i++) {
			if (ans >= (INTMAX / num_powered))
				throw new IllegalArgumentException("Input is to Large. Use Long.");
			ans *= num_powered;
		}
		return ans;
	}

	private static long pow(long num_powered, int index) {
		long ans = 1L;
		for (int i = 0; i < index; i++) {
			if (ans >= (LONGMAX / num_powered))
				throw new IllegalArgumentException("Input is to Large. Use PowP.");
			ans *= num_powered;
		}
		return ans;
	}

	private static long powP(long num_powered, long index, long p) {
		// O(log(index))
		// @Japanese 繰り返し二乗法
		if (num_powered == 0L)
			return 0L;
		if (index == 0L)
			return 1L;
		if (index == 2L) {
			return (pow2(num_powered) % p);
		}

		int d = getDigit2(index);
		long[] num_done_by2 = new long[d + 1];
		num_done_by2[0] = num_powered;
		for (int i = 1; i <= d; i++) {
			num_done_by2[i] = num_done_by2[i - 1] * num_done_by2[i - 1];
			num_done_by2[i] %= p;
		}
		long ans = 1L;
		for (int i = d; i >= 0; i--) {
			long cf = (1L << (long) i);
			if (index >= cf) {
				index -= cf;
				ans = ans * num_done_by2[i];
				ans %= p;
			}
		}
		return ans;
	}

	private static double hypod(double a, double b) {
		return Math.sqrt(a * a + b * b);
	}

	private static int getDigit2(long num2know) {
		// O(log(n))
		long compare4 = 1L;
		int digit = 0;
		while (num2know >= compare4) {
			digit++;
			compare4 = (1L << (long) digit);
		}
		return digit;
		// num < 2^digit
	}

	private static int getDigit10(long num2know) {
		// O(log10(n))
		long compare4 = 1L;
		int digit = 0;
		while (num2know >= compare4) {
			digit++;
			compare4 *= 10L;
		}
		return digit; // @Japanese num は digit桁の数で、10^digit未満

	}

	private static int divceil(int numerator, int denominator) {
		return (numerator + denominator - 1) / denominator;
	}

	private static long divceil(long numerator, long denominator) {
		return (numerator + denominator - 1L) / denominator;
	}

	private static long factorial(int n) {
		// O(n)
		long ans = 1L;
		for (long i = 2; i <= n; i++) {
			if (ans >= (LONGMAX / i))
				throw new IllegalArgumentException("Input is to Large. Use facP.");
			ans *= i;
		}
		return ans;
	}

	private static long facP(int n, long p) {
		// O(n) see also PermulationCombination:O(max_sz)+Q
		long ans = 1L;
		for (long i = 2; i <= n; i++) {
			ans *= i;
			ans %= p;
		}
		return ans;
	}

	private static long lcm(long m, long n) {
		long ans = m / gcd(m, n);
		if (ans >= (LONGMAX / n))
			throw new IllegalArgumentException("Input is to Large.");
		ans *= n;
		return ans;
	}

	private static long gcd(long m, long n) {
		// O(log(m+n))
		if ((m <= 0L) || (n <= 0L))
			throw new IllegalArgumentException("m and n should be natural.");

		while ((m > 0L) && (n > 0L)) {
			if (m >= n)
				m %= n;
			else
				n %= m;
		}
		if (m > 0L)
			return m;
		else
			return n;
	}

	private static boolean is_prime(long n2check) {
		// O(√n)
		if (n2check == 1L)
			return false;
		for (long i = 2L; i <= Math.sqrt(n2check); i++) {
			if (n2check % i == 0L)
				return false;
		}
		return true;
	}

	private static int safe_mod(int n, int p) {
		n %= p;
		if (n >= 0)
			return n;
		return (n + p);
	}

	private static long safe_mod(long n, long p) {
		n %= p;
		if (n >= 0L)
			return n;
		return (n + p);
	}

	private static long modinv(long n, long p) {
		// @Japanese 逆元を求める
		// O(10log(n))
		// pは素数でなくてもよい
		// ネットから拾ってきたのが理解不能だったので、行列計算を用いて非効率的アルゴリズムを書いた

		n %= p;
		if ((p == 1L) || (gcd(n, p) != 1L))
			throw new IllegalArgumentException("n and p should be coprime.");

		// @Japanese
		// yn≡1(mod p)
		// <-> xp+yn=1; (n<p)
		// ...(sx+ty)a+(ux+vy)b=1 (|sv-tu|=1)
		// ...(sx+ty)a+(ux+vy)=1
		// <- sx+ty=0, ux+vy=1

		long a = p, b = n, s = 1L, t = 0L, u = 0L, v = 1L;
		while (b > 1) {
			long quo = a / b, rem = a % b;
			a = b;
			b = rem;
			long s2 = s * quo + u, t2 = t * quo + v;
			u = s;
			v = t;
			s = s2;
			t = t2;
		}
		long det = s * v - t * u;
		if (abs(det) != 1L)
			throw new ArithmeticException("My algorithm was Wrong!!");
		s /= det;
		s %= p;
		if (s < 0L)
			s += p;
		return s;
	}

	private static int minAll(int[] dt4min) {
		// O(n)
		int min = INF;
		for (int element : dt4min) {
			if (element < min)
				min = element;
		}
		return min;
	}

	private static long minAll(long[] dt4min) {
		// O(n)
		long min = INFL;
		for (long element : dt4min) {
			if (element < min)
				min = element;
		}
		return min;
	}

	private static int maxAll(int[] dt4max) {
		// O(n)
		int max = -INF;
		for (int element : dt4max) {
			if (element > max)
				max = element;
		}
		return max;
	}

	private static long maxAll(long[] dt4max) {
		// O(n)
		long max = -INFL;
		for (long element : dt4max) {
			if (element > max)
				max = element;
		}
		return max;
	}

	private static int sumAll(int[] dt4sum) {
		// O(n)
		int sum_of_dt = 0;
		for (int element : dt4sum) {
			if (sum_of_dt > (INTMAX - element))
				throw new IllegalArgumentException("Input is to Large. Use Long.");
			sum_of_dt += element;
		}
		return sum_of_dt;
	}

	private static long sumAll(long[] dt4sum) {
		// O(n)
		long sum_of_dt = 0L;
		for (long element : dt4sum) {
			if (sum_of_dt > (LONGMAX - element))
				throw new IllegalArgumentException("Input is to Large.");
			sum_of_dt += element;
		}
		return sum_of_dt;
	}

	private static int sumAll(ArrayList<Integer> dt4sum) {
		int sum_of_dt = 0;
		for (long element : dt4sum) {
			if (sum_of_dt > (INTMAX - element))
				throw new IllegalArgumentException("Input is to Large. Use Long.");
			sum_of_dt += element;
		}
		return sum_of_dt;
	}

	private static int[] reverse(int[] as) {
		int ln = as.length;
		int[] bs = new int[ln];
		for (int i = 0; i < ln; i++)
			bs[i] = as[ln - i - 1];
		return bs;
	}

	private static void reverseSub(int[] as, int S_include, int Gnot_include) {
		// O(G-S)
		int ln = Gnot_include - S_include;

		int[] bs = new int[ln];
		for (int i = S_include; i < Gnot_include; i++)
			bs[i - S_include] = as[i];
		for (int i = 0; i < ln; i++)
			as[i + S_include] = bs[ln - i - 1];
	}

	private static boolean is_in_area(int y, int x, int height, int width) {
		if (y < 0)
			return false;
		if (x < 0)
			return false;
		if (y >= height)
			return false;
		if (x >= width)
			return false;
		return true;
	}

	private static boolean is_in_area(Vector v, int height, int width) {
		if (v.y < 0)
			return false;
		if (v.x < 0)
			return false;
		if (v.y >= height)
			return false;
		if (v.x >= width)
			return false;
		return true;
	}

	private static int nC2(int n) {
		return ((n * (n - 1)) / 2);
	}

	private static long nC2(long n) {
		return ((n * (n - 1L)) / 2L);
	}

	private static int iflag(int pos) {
		if (pos >= 32)
			throw new IllegalArgumentException("Input is to Large. Use Long.");
		return (1 << pos);
	}

	private static long flag(int pos) {
		if (pos >= 64)
			throw new IllegalArgumentException("Input is to Large. Use Long.");
		return (1L << (long) pos);
	}

	private static boolean isFlaged(int bit, int pos) {
		if (pos >= 32)
			throw new IllegalArgumentException("Input is to Large.");
		return ((bit & (1 << pos)) != 0);
	}

	private static boolean isFlaged(long bit, int pos) {
		if (pos >= 64)
			throw new IllegalArgumentException("Input is to Large.");
		return ((bit & (1L << (long) pos)) != 0L);
	}

	private static int deflag(int bit, int pos) {
		return (bit & (~(1 << pos)));
	}

	private static int countFlaged(int bit) {
		int ans = 0;
		for (int i = 0; i < 31; i++) {
			if ((bit & (1 << i)) != 0)
				ans++;
		}
		return ans;
	}

	private static int countFlaged(long bit) {
		int ans = 0;
		for (long i = 0L; i < 63L; i++) {
			if ((bit & (1L << i)) != 0L)
				ans++;
		}
		return ans;
	}

	private static int[] Xdir4 = { 1, 0, 0, -1 };
	private static int[] Ydir4 = { 0, 1, -1, 0 };
	private static int[] Xdir8 = { 1, 1, 1, 0, 0, -1, -1, -1 };
	private static int[] Ydir8 = { 1, 0, -1, 1, -1, 1, 0, -1 };

	public static int biSearch(int[] dt, int target) {
		// O(log(dt.length))
		// dt should be sorted in 0->INF
		// return adress of target
		int left = 0, right = dt.length - 1;
		int mid = -1;
		while (left <= right) {
			mid = ((right + left) / 2);
			if (dt[mid] == target)
				return mid;
			if (dt[mid] < target)
				left = (mid + 1);
			else
				right = (mid - 1);
		}
		return -1;
	}

	public static int biSearchMax(long[] dt, long target) {
		// O(log(dt.length))
		// dt should be sorted in 0->INF
		int left = -1, right = dt.length, mid = -1;
		while ((right - left) > 1) {
			mid = ((right + left) / 2);
			if (dt[mid] <= target)
				left = mid;
			else
				right = mid;
		}
		return left;
		// @Japanese target以下の最大のaddress
	}

	public static int biSearchMin(long[] dt, long target) {
		// O(log(dt.length))
		// dt should be sorted in 0->INF
		int left = -1, right = dt.length, mid = -1;
		while ((right - left) > 1) {
			mid = ((right + left) / 2);
			if (dt[mid] <= target)
				left = mid;
			else
				right = mid;
		}
		return right;
		// @Japanese targetより大きい最小のaddress
	}

	private static void fill(boolean[] target, boolean reset) {
		for (int i = 0; i < target.length; i++)
			target[i] = reset;
	}

	private static void fill(int[] target, int reset) {
		for (int i = 0; i < target.length; i++)
			target[i] = reset;
	}

	private static void fill(long[] target, long reset) {
		for (int i = 0; i < target.length; i++)
			target[i] = reset;
	}

	private static void fill(char[] target, char reset) {
		for (int i = 0; i < target.length; i++)
			target[i] = reset;
	}

	private static void fill(double[] target, double reset) {
		for (int i = 0; i < target.length; i++)
			target[i] = reset;
	}

	private static void fill(boolean[][] target, boolean reset) {
		for (int i = 0; i < target.length; i++) {
			for (int j = 0; j < target[i].length; j++) {
				target[i][j] = reset;
			}
		}
	}

	private static void fill(int[][] target, int reset) {
		for (int i = 0; i < target.length; i++) {
			for (int j = 0; j < target[i].length; j++) {
				target[i][j] = reset;
			}
		}
	}

	private static void fill(long[][] target, long reset) {
		for (int i = 0; i < target.length; i++) {
			for (int j = 0; j < target[i].length; j++) {
				target[i][j] = reset;
			}
		}
	}

	private static void fill(char[][] target, char reset) {
		for (int i = 0; i < target.length; i++) {
			for (int j = 0; j < target[i].length; j++) {
				target[i][j] = reset;
			}
		}
	}

	private static void fill(double[][] target, double reset) {
		for (int i = 0; i < target.length; i++) {
			for (int j = 0; j < target[i].length; j++) {
				target[i][j] = reset;
			}
		}
	}

	private static void fill(int[][][] target, int reset) {
		for (int i = 0; i < target.length; i++) {
			for (int j = 0; j < target[i].length; j++) {
				for (int k = 0; k < target[i][j].length; k++) {
					target[i][j][k] = reset;
				}
			}
		}
	}

	private static void fill(long[][][] target, long reset) {
		for (int i = 0; i < target.length; i++) {
			for (int j = 0; j < target[i].length; j++) {
				for (int k = 0; k < target[i][j].length; k++) {
					target[i][j][k] = reset;
				}
			}
		}
	}

	private static void fill_parent(int[] parent) {
		for (int i = 0; i < parent.length; i++) {
			parent[i] = i;
		}
	}

	private static void showBit(int bit) {
		for (int i = 0; i < getDigit2(bit); i++) {
			if (isFlaged(bit, i))
				System.out.print("O");
			else
				System.out.print(".");
		}
		System.out.println();
	}

	private static void showBit(long bit) {
		for (int i = 0; i < getDigit2(bit); i++) {
			if (isFlaged(bit, i))
				System.out.print("O");
			else
				System.out.print(".");
		}
		System.out.println();
	}

	static void show2(boolean[][] dt, String cmnt) {
		for (int i = 0; i < dt.length; i++) {
			for (int j = 0; j < dt[i].length; j++) {
				if (dt[i][j])
					System.out.print("O");
				else
					System.out.print(".");
			}
			if (!cmnt.equals(""))
				System.out.print("<-" + cmnt);
			System.out.println(" :" + i);
		}
	}

	static void show2(int[][] dt, String cmnt) {
		for (int i = 0; i < dt.length; i++) {
			for (int j = 0; j < dt[i].length; j++)
				System.out.print(dt[i][j] + ",");
			if (!cmnt.equals(""))
				System.out.print("<-" + cmnt);
			System.out.println(" :" + i);
		}
	}

	static void show2(long[][] dt, String cmnt) {
		for (int i = 0; i < dt.length; i++) {
			for (int j = 0; j < dt[i].length; j++)
				System.out.print(dt[i][j] + ",");
			if (!cmnt.equals(""))
				System.out.print("<-" + cmnt);
			System.out.println(" :" + i);
		}
	}

	static void show2(ArrayDeque<Long> dt) {
		long element = 0;
		while (dt.size() > 0) {
			element = dt.removeFirst();
			System.out.print(element);
		}
		System.out.println("\n");
	}

	static void show2(List<Object> dt) {
		for (int i = 0; i < dt.size(); i++)
			System.out.print(dt.get(i) + ",");
		System.out.println("\n");
	}

	private static void prtlnas(int[] array) {
		PrintWriter out = new PrintWriter(System.out);
		for (int e: array)
			out.println(e);
		out.flush();
	}

	private static void prtlnas(long[] array) {
		PrintWriter out = new PrintWriter(System.out);
		for (long e: array)
			out.println(e);
		out.flush();
	}

	private static void prtlnas(ArrayList<Object> array) {
		PrintWriter out = new PrintWriter(System.out);
		for (Object e: array)
			out.println(e);
		out.flush();
	}

	private static void prtspas(int[] array) {
		PrintWriter out = new PrintWriter(System.out);
		out.print(array[0]);
		for (int i = 1; i < array.length; i++)
			out.print(" " + array[i]);
		out.println();
		out.flush();
	}

	private static void prtspas(long[] array) {
		PrintWriter out = new PrintWriter(System.out);
		out.print(array[0]);
		for (int i = 1; i < array.length; i++)
			out.print(" " + array[i]);
		out.println();
		out.flush();
	}

	private static void prtspas(double[] array) {
		PrintWriter out = new PrintWriter(System.out);
		out.print(array[0]);
		for (int i = 1; i < array.length; i++)
			out.print(" " + array[i]);
		out.println();
		out.flush();
	}

	private static void prtspas(ArrayList<Integer> array) {
		if (array.isEmpty())
			return;
		PrintWriter out = new PrintWriter(System.out);
		out.print(array.get(0));
		for (int i = 1; i < array.size(); i++)
			out.print(" " + array.get(i));
		out.println();
		out.flush();
	}

	static class Vector {
		int x, y;

		public Vector(int sx, int sy) {
			this.x = sx;
			this.y = sy;
		}

		public boolean equals(Vector v) {
			return (this.x == v.x && this.y == v.y);
		}

		public void show2() {
			System.out.println(this.x + ", " + this.y);
		}

		public static int dist2(Vector a, Vector b) {
			int dx = abs(a.x - b.x);
			int dy = abs(a.y - b.y);
			if (dx > 3e4)
				throw new IllegalArgumentException("Input is to Large. Use Long.");
			if (dy > 3e4)
				throw new IllegalArgumentException("Input is to Large. Use Long.");
			return (dx * dx + dy * dy);
		}
	}

	static class CompVector implements Comparator<Vector> {
		public int compare(Vector a, Vector b) {
			if (a.x == b.x)
				return a.y - b.y;
			else
				return a.x - b.x;
		}
	}

	static class FastScanner {
		//@Japanese ネットから拾ってきた。よく分からん。
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private static boolean isPrintableChar(int c) {
			return (33 <= c) && (c <= 126);
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nexL() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b) || b == ':') {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nexI() {
			long nl = nexL();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
				throw new NumberFormatException();
			}
			return (int) nl;
		}

		public double nexD() {
			return Double.parseDouble(next());
		}

		// a means array
		public void ai(int[]... array) {
			for (int i = 0; i < array[0].length; i++) {
				for (int j = 0; j < array.length; j++) {
					array[j][i] = nexI();
				}
			}
			return;
		}

		public void al(long[]... array) {
			for (int i = 0; i < array[0].length; i++) {
				for (int j = 0; j < array.length; j++) {
					array[j][i] = nexL();
				}
			}
			return;
		}

		public void aimin1(int[] array) {
			for (int i = 0; i < array.length; i++) {
				array[i] = nexI() - 1;
			}
			return;
		}

		public void aD(double[] array) {
			for (int i = 0; i < array.length; i++) {
				array[i] = nexD();
			}
			return;
		}

		public void ai2d(int[][] array) {
			for (int i = 0; i < array.length; i++) {
				for (int j = 0; j < array[0].length; j++) {
					array[i][j] = nexI();
				}
			}
			return;
		}

		public void al2d(long[][] array) {
			for (int i = 0; i < array.length; i++) {
				for (int j = 0; j < array[0].length; j++) {
					array[i][j] = nexL();
				}
			}
			return;
		}
	}
}
// END OF THE CODE


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            final int[] dr = {-1, 0, 1, 0};
            final int[] dc = {0, -1, 0, 1};

            int height = in.nextInt();
            int width = in.nextInt();
            int k = in.nextInt();

            int[][][] cost = new int[4][height][width];
            for (int r = 0; r < height; r++) {
                for (int c = 0; c + 1 < width; c++) {
                    int x = in.nextInt();
                    cost[3][r][c] = x;
                    cost[1][r][c + 1] = x;
                }
            }

            for (int r = 0; r + 1 < height; r++) {
                for (int c = 0; c < width; c++) {
                    int x = in.nextInt();
                    cost[2][r][c] = x;
                    cost[0][r + 1][c] = x;
                }
            }

            boolean odd = (k % 2 != 0);
            k /= 2;
            int[][][] d = new int[k + 1][height][width];
            for (int len = 1; len <= k; len++) {
                for (int r = 0; r < height; r++) {
                    for (int c = 0; c < width; c++) {
                        d[len][r][c] = Integer.MAX_VALUE;
                        for (int dir = 0; dir < 4; dir++) {
                            int nr = r + dr[dir];
                            int nc = c + dc[dir];
                            if (nr < 0 || nr >= height || nc < 0 || nc >= width) {
                                continue;
                            }
                            d[len][r][c] = Math.min(d[len][r][c], d[len - 1][nr][nc] + cost[dir][r][c]);
                        }
                    }
                }
            }

            for (int r = 0; r < height; r++) {
                for (int c = 0; c < width; c++) {
                    if (c > 0) {
                        out.print(" ");
                    }
                    out.print(odd ? -1 : 2 * d[k][r][c]);
                }
                out.println();
            }
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}