import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;

public class Main {
    static public void main(String args[]) throws Exception {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(), m = s.nextInt(), K = s.nextInt();
        int[][] p = new int[n][m - 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m - 1; j++) {
                p[i][j] = s.nextInt();
            }
        }
        int[][] v = new int[n - 1][m];
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < m; j++) {
                v[i][j] = s.nextInt();
            }
        }
        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;
        }

        long[][][] dp = new long[K + 1][n][m];
        for (int k = 2; k <= K; k += 2) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    long res = Long.MAX_VALUE;
                    if (i + 1 < n) {
                        res = Math.min(res, dp[k - 2][i + 1][j] + v[i][j] * 2);
                    }
                    if (i - 1 >= 0) {
                        res = Math.min(res, dp[k - 2][i - 1][j] + v[i - 1][j] * 2);
                    }
                    if (j + 1 < m) {
                        res = Math.min(res, dp[k - 2][i][j + 1] + p[i][j] * 2);
                    }

                    if (j - 1 >= 0) {
                        res = Math.min(res, dp[k - 2][i][j - 1] + p[i][j - 1] * 2);
                    }
                    dp[k][i][j] = res;
                }
            }
        }

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

    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
public class Main{
    static InputReader sc;
    static PrintWriter pw;
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        sc = new InputReader(inputStream);
        pw = new PrintWriter(outputStream);
        solve();
        pw.close();
    }
    // static int L,R,top,bottom;
    // static int cnt,edge;
    // static long ans;
    public static void solve() {
        // int t=sc.nextInt();
        int t=1;
        u:while(t-->0){
            int n=s(0);
            int m=s(0);
            int k=s(0);
            long [][][]arr=new long [n][m][4];
            for(int i=0;i<n;i++){
                for(int j=0;j<m-1;j++){
                    long v=s(0l);
                    arr[i][j][0]=v;
                    arr[i][j+1][2]=v;
                }
            }
            for(int i=0;i<n-1;i++){
                for(int j=0;j<m;j++){
                    long v=s(0l);
                    arr[i][j][1]=v;
                    arr[i+1][j][3]=v;
                }
            }
            Long [][][]dp=new Long [n][m][k+1];
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++)
                    for(int p=1;p<=k;p++)
                        helper(i,j,p,dp,arr,n,m);
            }
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++)
                    p(dp[i][j][k]+" ");
                pln("");
            }
        }
    }
    static int [][]dir=new int [][]{{0,1},{1,0},{0,-1},{-1,0}};
    public static long helper(int i, int j, int k, Long [][][]dp, long [][][]arr, int n, int m){
        if(k<0)
            return -1;
        if(k==0)
            return 0;
        if(dp[i][j][k]!=null)
            return dp[i][j][k];
        int x, y;
        long ans=Long.MAX_VALUE,val;
        for(int d=0;d<4;d++){
            x=i+dir[d][0];
            y=j+dir[d][1];
            if(x<0||x>=n||y<0||y>=m)
                continue;
            val=helper(x,y,k-2,dp,arr,n,m);
            if(val!=-1)
                ans=Math.min(ans,val+2*arr[i][j][d]);
        }
        return dp[i][j][k]=(ans==Long.MAX_VALUE?-1:ans);
    }
    public static int find(List<Integer> list, int x){
        int l=0,r=list.size()-1,m;
        while(l<=r){
            m=(r-l)/2+l;
            if(list.get(m)<=x)
                l=m+1;
            else
                r=m-1;
        }
        return r;
    }
    static class Node{
        int val;
        long cost;
        Node next;
        Node(int v,long c){
            val=v;
            next=null;
            cost=c;
        }
    }
    public static long sum(long n){
        long val=0l;
        while(n>0){
            val+=n%10;
            n/=10;
        }
        return val;
    }
    // static class Node{
    //     int left,right;
    //     Node prev,next;
    //     Node(int i, int v){
    //         left=i;
    //         right=v;
    //         prev=next=null;
    //     }
    //     void remove(){
    //         this.prev.next=this.next;
    //         this.next.prev=this.prev;
    //     }
    //     void insert(Node node){
    //         node.next=this;
    //         node.prev=this.prev;
    //         node.prev.next=node;
    //         this.prev=node;
    //     }
    // }
    public static int  findDiameter(int r, List<List<Integer>>list){
        return findFarthest(findFarthest(r,list)[0],list)[1];
    }
    public static int[] findFarthest(int u, List<List<Integer>>list){
        int n=list.size();
        boolean []vis=new boolean[n+1];
        Queue<Integer>q=new LinkedList<>();
        q.offer(u);
        vis[u]=true;
        int s,pr,cnt=0;
        int []ar=new int[]{u,0};
        while(q.size()>0){
            s=q.size();
            while(s-->0){
                pr=q.poll();
                if(ar[1]<cnt){
                    ar[1]=cnt;
                    ar[0]=pr;
                }
                for(int i:list.get(pr)){
                    if(!vis[i]){
                        vis[i]=true;
                        q.offer(i);
                    }
                }
            }
            cnt++;
        }
        return ar;
    }
    public static long atMostK(char []chrr, int k){
        if(k<0)
            return 0;
        int l=0,cnt=0;
        long ans=0l;
        for(int i=0;i<chrr.length;i++){
            if(chrr[i]=='1')
                cnt++;
            while(cnt>k){
                if(chrr[l++]=='1')
                    cnt--;
            }
            ans+=(long)(i-l)+1l;
        }
        return ans;
    }
    public static int ask(int l){
        System.out.println(l);
        System.out.flush();
        return sc.nextInt();
    }
    public static void sort(long []arr){
        ArrayList<Long> list=new ArrayList<>();
        for(int i=0;i<arr.length;i++)
            list.add(arr[i]);
        Collections.sort(list);
        for(int i=0;i<arr.length;i++)
            arr[i]=list.get(i);
    }
    public static void swap(char []chrr, int i, int j){
        char temp=chrr[i];
        chrr[i]=chrr[j];
        chrr[j]=temp;
    }
    public static int countSetBits(long n){
        int a=0;
        while(n>0){
            a+=(n&1);
            n>>=1;
        }
        return a;
    }
    static class Pair{
        int v,w;
        Pair(int V, int W){
            v=V;
            w=W;
        }
     //*
    }
    /*/
        public int compareTo(Pair p){
            return (b-p.b);
        }
        public int hashCode(){
            int hashcode = (a+" "+b).hashCode();
            return hashcode;
        }
        public boolean equals(Object obj){
            if (obj instanceof Pair) {
                Pair p = (Pair) obj;
                return (p.a==this.a && p.b == this.b);
            }
            return false;
        }
    }
    //*/
    static boolean isPrime(long n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;
        if (n % 2 == 0 || n % 3 == 0)
            return false;
        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;
        return true;
    }
    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return a>b?gcd(b, a % b):gcd(a, b % a);
    }
    static long fast_pow(long base,long n,long M){
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }
    static long modInverse(long n,long M){
        return fast_pow(n,M-2,M);
    }
    public static int s(int n){
        return sc.nextInt();
    }
    public static long s(long n){
        return sc.nextLong();
    }
    public static String s(String n){
        return sc.next();
    }
    public static double s(double n){
        return sc.nextDouble();
    }
    public static void p(int n){
        pw.print(n);
    }
    public static void p(long n){
        pw.print(n);
    }
    public static void p(String n){
        pw.print(n);
    }
    public static void p(double n){
        pw.print(n);
    }
    public static void pln(int n){
        pw.println(n);
    }
    public static void pln(long n){
        pw.println(n);
    }
    public static void pln(String n){
        pw.println(n);
    }
    public static void pln(double n){
        pw.println(n);
    }
    public static void feedArr(long []arr){
        for(int i=0;i<arr.length;i++)
            arr[i]=sc.nextLong();
    }
    public static void feedArr(double []arr){
        for(int i=0;i<arr.length;i++)
            arr[i]=sc.nextDouble();
    }
    public static void feedArr(int []arr){
        for(int i=0;i<arr.length;i++)
            arr[i]=sc.nextInt();
    }
    public static void feedArr(String []arr){
        for(int i=0;i<arr.length;i++)
            arr[i]=sc.next();
    }
    public static String printArr(int []arr){
        StringBuilder sbr=new StringBuilder();
        for(int i:arr)
            sbr.append(i+" ");
        return sbr.toString();
    }
    public  static String printArr(long []arr){
        StringBuilder sbr=new StringBuilder();
        for(long i:arr)
            sbr.append(i+" ");
        return sbr.toString();
    }
    public static String printArr(String []arr){
        StringBuilder sbr=new StringBuilder();
        for(String i:arr)
            sbr.append(i+" ");
        return sbr.toString();
    }
    public static String printArr(double []arr){
        StringBuilder sbr=new StringBuilder();
        for(double i:arr)
            sbr.append(i+" ");
        return sbr.toString();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;

public class D_Rnd718_Explorer
{
	static int row, col;
	static int INF = 1_000_000_000;
	static int[] dx = {0, 0, 1, -1};
	static int[] dy = {1, -1, 0, 0};
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

		String[] in = scan.readLine().split(" ");
		row = parse(in[0]);
		col = parse(in[1]);
		int k = parse(in[2]);

		int[][] xMove = new int[row][col-1];
		for(int i = 0; i < row; i++)
		{
			in = scan.readLine().split(" ");
			for(int j = 0; j < col - 1; j++)
				xMove[i][j] = parse(in[j]);
		}

		int[][] yMove = new int[row - 1][col];
		for(int i = 0; i < row - 1; i++)
		{
			in = scan.readLine().split(" ");
			for(int j = 0; j < col; j++)
				yMove[i][j] = parse(in[j]);
		}

		int[][] output = new int[row][col];

		if(k % 2 != 0)
			fill(-1, output);

		else
		{
			Point[][] grid = new Point[row][col];
			for(int i = 0; i < row; i++)
				for(int j = 0; j < col; j++)
					grid[i][j] = new Point(i, j);

			parseMoves(grid, xMove, yMove);

			solve(grid, k, output);
		}

		print(output, out);

		out.flush();
	}

	private static void solve(Point[][] grid, int k, int[][] output)
	{
		// try bfs (hoping it passes the time constraint)
		/*int target = k / 2;
		for(int i = 0; i < row; i++)
			for(int j = 0; j < col; j++)
				output[i][j] = bfs(j, i, target, grid) << 1;*/
		int target = k / 2;
		int[][][] dist = new int[row][col][k/2];
		fill(dist, grid);

		for(int steps = 1; steps < target; steps++ )
		{
			for(int i = 0; i < row; i++)
			{
				for(int j = 0; j < col;j ++)
				{
					dist[i][j][steps] = getDist(i, j, steps, dist, grid);
				}
			}
		}

		for(int i = 0; i < row; i++)
			for(int j = 0; j < col;j ++)
				output[i][j] = (dist[i][j][target - 1] << 1);

	}

	private static int getDist(int y, int x, int steps, int[][][] dist, Point[][] grid)
	{
		for(int d = 0; d < 4; d++)
		{
			int i = y + dy[d];
			int j = x + dx[d];

			if(valid(i, j))
			{
				dist[y][x][steps] = Math.min(dist[y][x][steps], dist[i][j][steps - 1] + grid[y][x].weight[d]);
			}
		}

		return dist[y][x][steps];
	}

	private static void fill(int[][][] dist, Point[][] grid)
	{
		for(int i = 0; i < row; i++)
			for(int j = 0; j < col;j ++)
				for(int s = 0; s < dist[0][0].length; s++)
					dist[i][j][s] = INF;

		for(int i = 0; i < row; i++)
			for(int j = 0; j < col; j++)
				for(int d = 0; d < 4; d++)
					dist[i][j][0] = Math.min(dist[i][j][0], grid[i][j].weight[d]);

	}

	private static boolean valid(int y, int x)
	{
		return y >= 0 && x >= 0 && y < row && x < col;
	}

	/*private static int bfs(int xStart, int yStart, int target, Point[][] grid)
	{
		PriorityQueue<Step> q = new PriorityQueue<Step>();
		q.add(new Step(grid[yStart][xStart], 0, 0));

		Step s;
		int w;
		while(!q.isEmpty())
		{
			s = q.poll();

			if(s.numSteps == target)
				return s.length;

			// try to go in each of the four directions
			for(int d = 0; d < 4; d++)
			{
				w = s.current.weight[d];
				if(w != -1)
					q.add(new Step(grid[s.current.y + s.current.dy[d]][s.current.x + s.current.dx[d]], s.length + w, s.numSteps + 1));
			}
		}

		return -1;
	}*/

	private static void parseMoves(Point[][] grid, int[][] xMove, int[][] yMove)
	{
		for(int i = 0; i < xMove.length; i++)
		{
			for(int j = 0; j < xMove[i].length; j++)
			{
				grid[i][j].weight[2] = xMove[i][j];	// right
				grid[i][j + 1].weight[3] = xMove[i][j]; // left
			}
		}

		for(int i = 0; i < yMove.length; i++)
		{
			for(int j = 0; j < yMove[i].length; j++)
			{
				grid[i][j].weight[0] = yMove[i][j];	// down
				grid[i + 1][j].weight[1] = yMove[i][j]; // up
			}
		}
	}

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

	private static void print(int[][] ray, PrintWriter out)
	{
		for(int i = 0; i < ray.length; i++)
		{
			out.print(ray[i][0]);
			for(int j = 1; j < ray[i].length; j++)
				out.print(" " + ray[i][j]);
			out.println();
		}

	}

	public static int parse(String num)
	{
		return Integer.parseInt(num);
	}

	static class Point
	{

		int[] weight = new int[4];		// down, up, right, left
		int x, y;

		public Point(int i, int j)
		{
			y = i;
			x = j;
			Arrays.fill(weight, INF);
		}
	}

	static class Step implements Comparable<Step>
	{
		int length, numSteps;
		Point current;

		public Step(Point p, int weight, int s)
		{
			current = p;
			length = weight;
			numSteps = s;
		}

		@Override
		public int compareTo(Step s)
		{
			if(length == s.length)  return numSteps - s.numSteps;
			return length - s.length;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DExplorerSpace solver = new DExplorerSpace();
        solver.solve(1, in, out);
        out.close();
    }

    static class DExplorerSpace {
        int n;
        int m;
        int k;
        int[][] col;
        int[][] row;
        long[][][] memo;

        public void readInput(Scanner sc) {
            n = sc.nextInt();
            m = sc.nextInt();
            k = sc.nextInt();
            col = new int[n][m - 1];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m - 1; j++)
                    col[i][j] = sc.nextInt();
            row = new int[n - 1][m];
            for (int i = 0; i < n - 1; i++)
                for (int j = 0; j < m; j++)
                    row[i][j] = sc.nextInt();
        }

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int q = 1;
            while (q-- > 0) {
                readInput(sc);
                if (k % 2 == 1) {
                    for (int i = 0; i < n; i++) {
                        for (int j = 0; j < m; j++)
                            pw.print(-1 + " ");
                        pw.println();
                    }
                    return;
                }
                memo = new long[k + 1][n][m];
                for (long[][] x : memo)
                    for (long[] y : x)
                        Arrays.fill(y, -1);
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < m; j++) {
                        pw.print(2l * dp(i, j, k / 2) + " ");
                    }
                    pw.println();
                }
            }
        }

        private long dp(int i, int j, int rem) {
            if (rem == 0)
                return 0;
            if (memo[rem][i][j] != -1)
                return memo[rem][i][j];
            long min = (long) 1e18;
            if (j <= m - 2)
                min = Math.min(min, col[i][j] + dp(i, j + 1, rem - 1));
            if (j > 0)
                min = Math.min(min, col[i][j - 1] + dp(i, j - 1, rem - 1));
            if (i <= n - 2)
                min = Math.min(min, row[i][j] + dp(i + 1, j, rem - 1));
            if (i > 0)
                min = Math.min(min, row[i - 1][j] + dp(i - 1, j, rem - 1));
            return memo[rem][i][j] = min;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

    }
}


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

public class D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int t = 1;
        for (int i = 0; i < t; i++) {
            solve(sc, pw);
        }
        pw.close();
    }
    static void solve(Scanner in, PrintWriter out){
        int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
        int[][] ri = new int[n][m - 1];
        int[][] dn = new int[n - 1][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m - 1; j++) {
                ri[i][j] = in.nextInt();
            }
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < m; j++) {
                dn[i][j] = in.nextInt();
            }
        }
        long[][][] dp = new long[n][m][k + 1];
        if (k % 2 == 1){
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    out.print(-1 +" ");
                }
                out.println();
            }
        }else{
            for (int l = 2; l <= k; l += 2) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < m; j++) {
                        long dm = Long.MAX_VALUE;
                        if (i > 0){
                            int pi = i - 1, pj = j;
                            dm = Math.min(dm, dp[pi][pj][l - 2] + dn[pi][pj] * 2);
                        }
                        if (j > 0){
                            int pi = i ,pj = j - 1;
                            dm = Math.min(dm, dp[pi][pj][l - 2] + ri[pi][pj] * 2);
                        }
                        if (i < n - 1){
                            dm = Math.min(dm, dp[i + 1][j][l - 2] + dn[i][j] * 2);
                        }
                        if (j < m - 1){
                            dm = Math.min(dm, dp[i][j + 1][l - 2] + ri[i][j] * 2);
                        }
                        dp[i][j][l] = dm;
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (dp[i][j][k] == Long.MAX_VALUE){
                        out.print(-1 +" ");
                    }else{
                        out.print(dp[i][j][k] +" ");
                    }
                }
                out.println();
            }
        }

    }

    static boolean isPrime(long n)
    {
        // Corner cases
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    // method to return LCM of two numbers
    static long lcm(long a, long b)
    {
        return (a / gcd(a, b)) * b;
    }

    public static int[] sieveEratosthenes(int n) {
        if (n <= 32) {
            int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
            for (int i = 0; i < primes.length; i++) {
                if (n < primes[i]) {
                    return Arrays.copyOf(primes, i);
                }
            }
            return primes;
        }

        int u = n + 32;
        double lu = Math.log(u);
        int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];
        ret[0] = 2;
        int pos = 1;

        int[] isnp = new int[(n + 1) / 32 / 2 + 1];
        int sup = (n + 1) / 32 / 2 + 1;

        int[] tprimes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
        for (int tp : tprimes) {
            ret[pos++] = tp;
            int[] ptn = new int[tp];
            for (int i = (tp - 3) / 2; i < tp << 5; i += tp) ptn[i >> 5] |= 1 << (i & 31);
            for (int j = 0; j < sup; j += tp) {
                for (int i = 0; i < tp && i + j < sup; i++) {
                    isnp[j + i] |= ptn[i];
                }
            }
        }

        // 3,5,7
        // 2x+3=n
        int[] magic = {0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14};
        int h = n / 2;
        for (int i = 0; i < sup; i++) {
            for (int j = ~isnp[i]; j != 0; j &= j - 1) {
                int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];
                int p = 2 * pp + 3;
                if (p > n) break;
                ret[pos++] = p;
                if ((long) p * p > n) continue;
                for (int q = (p * p - 3) / 2; q <= h; q += p) isnp[q >> 5] |= 1 << q;
            }
        }

        return Arrays.copyOf(ret, pos);
    }

    //    reverse division for 2
    public static long[] rdiv2(int n, int mod){
        long[] arr = new long[n + 5];
        arr[0] = 1;
        long rev2 = (mod + 1) / 2;
        for (int i = 1; i < n; i++) {
            arr[i] = arr[i - 1] * rev2 % mod;
        }
        return arr;
    }
    static List<Integer> primeFactors(int n)
    {
        // Print the number of 2s that divide n
        List<Integer> ls = new ArrayList<>();
        if (n % 2 == 0) ls.add(2);
        while (n%2==0)
        {
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            if (n  % i == 0) ls.add(i);
            while (n%i == 0)
            {
                n /= i;
            }
        }
        if (n > 1) ls.add(n);
        return ls;
    }
}


import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;

public class D {

    private static void run() throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int p = in.nextInt();

        int[] dx = {1, -1, 0, 0};
        int[] dy = {0, 0, 1, -1};
        int[][][] map = new int[n][m][4];

        ArrayList<Edge> edges = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m - 1; j++) {
                int len = in.nextInt();
                edges.add(new Edge(new Point[]{new Point(i, j), new Point(i, j + 1)}, len));
                map[i][j][2] = map[i][j + 1][3] = len;
            }
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < m; j++) {
                int len = in.nextInt();
                edges.add(new Edge(new Point[]{new Point(i, j), new Point(i + 1, j)}, len));
                map[i][j][0] = map[i + 1][j][1] = len;
            }
        }
        if (p % 2 != 0) {
            int[] ans = new int[m];
            for (int i = 0; i < m; i++) {
                ans[i] = -1;
            }
            for (int i = 0; i < n; i++) {
                print_array(ans);
            }
            return;
        }

        edges.sort(Comparator.comparingInt(o -> o.len));

        int[][][] dp = new int[2][n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int min = Integer.MAX_VALUE;
                for (int k = 0; k < 4; k++) {
                    if (map[i][j][k] == 0) continue;
                    min = Math.min(min, map[i][j][k]);
                }
                dp[1][i][j] = min * 2;
            }
        }

        for (int k = 2; k <= p / 2; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    dp[k & 1][i][j] = Integer.MAX_VALUE;
                    for (int d = 0; d < 4; d++) {
                        int nx = i + dx[d];
                        int ny = j + dy[d];
                        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;

                        dp[k & 1][i][j] = Math.min(dp[(k - 1) & 1][nx][ny] + map[i][j][d] * 2, dp[k&1][i][j]);
                    }
                }
            }
        }

        for (int i = 0; i < n; i++) {
            print_array(dp[(p / 2) & 1][i]);
        }
    }

    static class Edge {
        Point[] points;
        int len;

        public Edge(Point[] points, int len) {
            this.points = points;
            this.len = len;
        }
    }

    static class Point {
        final int x, y;

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

    }

    public static void main(String[] args) throws IOException {
        in = new Reader();
        out = new PrintWriter(new OutputStreamWriter(System.out));

//        int t = in.nextInt();
//        for (int i = 0; i < t; i++) {
//        }
        run();

        out.flush();
        in.close();
        out.close();
    }

    private static int gcd(int a, int b) {
        if (a == 0 || b == 0)
            return 0;
        while (b != 0) {
            int tmp;
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    static final long mod = 1000000007;

    static long pow_mod(long a, long b) {
        long result = 1;
        while (b != 0) {
            if ((b & 1) != 0) result = (result * a) % mod;
            a = (a * a) % mod;
            b >>= 1;
        }
        return result;
    }

    private static long multiplied_mod(long... longs) {
        long ans = 1;
        for (long now : longs) {
            ans = (ans * now) % mod;
        }
        return ans;
    }

    @SuppressWarnings("FieldCanBeLocal")
    private static Reader in;
    private static PrintWriter out;

    private static void print_array(int[] array) {
        for (int now : array) {
            out.print(now);
            out.print(' ');
        }
        out.println();
    }

    private static void print_array(long[] array) {
        for (long now : array) {
            out.print(now);
            out.print(' ');
        }
        out.println();
    }

    static class Reader {
        private static final int BUFFER_SIZE = 1 << 16;
        private final DataInputStream din;
        private final byte[] buffer;
        private int bufferPointer, bytesRead;

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

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

        public int nextSign() throws IOException {
            byte c = read();
            while ('+' != c && '-' != c) {
                c = read();
            }
            return '+' == c ? 0 : 1;
        }

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

        public int skip() throws IOException {
            int b;
            // noinspection ALL
            while ((b = read()) != -1 && isSpaceChar(b)) {
                ;
            }
            return b;
        }

        public char nc() throws IOException {
            return (char) skip();
        }

        public String next() throws IOException {
            int b = skip();
            final StringBuilder sb = new StringBuilder();
            while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            final 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();
            }
            final 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();
            }
            final 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 {
            din.close();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            DExplorerSpace solver = new DExplorerSpace();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DExplorerSpace {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.ri();
            int m = in.ri();
            int k = in.ri();
            int[][] lr = new int[n][m - 1];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m - 1; j++) {
                    lr[i][j] = in.ri();
                }
            }
            int[][] ud = new int[n - 1][m];
            for (int i = 0; i < n - 1; i++) {
                for (int j = 0; j < m; j++) {
                    ud[i][j] = in.ri();
                }
            }

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

            k /= 2;
            int inf = (int) 1e9;
            int[][][] dp = new int[k + 1][n][m];
            for (int i = 1; i <= k; i++) {
                for (int j = 0; j < n; j++) {
                    for (int t = 0; t < m; t++) {
                        dp[i][j][t] = inf;
                        //left
                        if (t > 0) {
                            dp[i][j][t] = Math.min(dp[i][j][t], dp[i - 1][j][t - 1] + lr[j][t - 1]);
                        }
                        //right
                        if (t + 1 < m) {
                            dp[i][j][t] = Math.min(dp[i][j][t], dp[i - 1][j][t + 1] + lr[j][t]);
                        }
                        //bot
                        if (j + 1 < n) {
                            dp[i][j][t] = Math.min(dp[i][j][t], dp[i - 1][j + 1][t] + ud[j][t]);
                        }
                        //top
                        if (j > 0) {
                            dp[i][j][t] = Math.min(dp[i][j][t], dp[i - 1][j - 1][t] + ud[j - 1][t]);
                        }
                    }
                }
            }

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    out.append(dp[k][i][j] * 2).append(' ');
                }
                out.println();
            }
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private static final int THRESHOLD = 32 << 10;
        private final Writer os;
        private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        private void afterWrite() {
            if (cache.length() < THRESHOLD) {
                return;
            }
            flush();
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput println() {
            return append('\n');
        }

        public FastOutput flush() {
            try {
//            boolean success = false;
//            if (stringBuilderValueField != null) {
//                try {
//                    char[] value = (char[]) stringBuilderValueField.get(cache);
//                    os.write(value, 0, cache.length());
//                    success = true;
//                } catch (Exception e) {
//                }
//            }
//            if (!success) {
                os.append(cache);
//            }
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int ri() {
            return readInt();
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}


import java.util.*;
public class temp {
    public static void main(String str[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int arr[][] = new int[n][m];
        int cross[][] = new int[n][m-1];
        int up[][] = new int[n-1][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m-1;j++){
                cross[i][j] = sc.nextInt();
            }
        }
        for(int i=0;i<n-1;i++){
            for(int j=0;j<m;j++){
                up[i][j] = sc.nextInt();
            }
        }
        int[][] fans = new int[n][m];
            if (k % 2 != 0) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < m; j++) {
                        fans[i][j] = -1;
                    }
                }
            }
            else {
                int[][][] ans = new int[(k/2)+1][n][m];
                for (int l = 1; l <= k / 2; l++){
                    for (int i = 0; i < n ; i++) {
                        for (int j = 0; j < m; j++) {
                            int min = Integer.MAX_VALUE;
                            if(i>0){
                                min = Math.min(min, up[i-1][j] + ans[l-1][i-1][j]);
                            }
                            if(j>0){
                                min = Math.min(min, cross[i][j-1] + ans[l-1][i][j-1]);
                            }
                            if(i<n-1){
                                min = Math.min(min, up[i][j] + ans[l-1][i+1][j]);
                            }
                            if(j<m-1){
                                min = Math.min(min, cross[i][j] + ans[l-1][i][j+1]);
                            }
                            ans[l][i][j] = min;
                        }
                    }
                }
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < m; j++) {
                        fans[i][j] = 2*ans[k/2][i][j];
                    }
                }
            }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                System.out.print(fans[i][j]+" ");
            }
            System.out.println();
        }

    }

}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;
import java.util.function.Predicate;

public class Main{
    public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    static long MOD = (long) (1e9 + 7);
    //    static long MOD = 998244353;
    static long MOD2 = MOD * MOD;
    static FastReader sc = new FastReader();
    static int pInf = Integer.MAX_VALUE;
    static int nInf = Integer.MIN_VALUE;
    static long ded = (long)(1e17)+9;
    public static void main(String[] args) throws Exception {
        int test = 1;
//        test = sc.nextInt();
        for (int i = 1; i <= test; i++){
//            out.print("Case #"+i+": ");
            solve();
        }
        out.flush();
        out.close();
    }
    static int n,m;
    static int[][] hor,ver;
    static Long[][][] dp;
    static void solve(){
        n = sc.nextInt();
        m = sc.nextInt();
        int k = sc.nextInt();
        dp = new Long[n+1][m+1][k+1];
        hor = new int[n][m-1];
        ver = new int[n-1][m];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m-1; j++){
                hor[i][j] = sc.nextInt();
            }
        }
        for(int i = 0; i < n-1; i++){
            for(int j = 0; j < m; j++){
                ver[i][j] = sc.nextInt();
            }
        }
        if(k%2==1){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < m; j++){
                    out.print(-1+" ");
                }
                out.println();
            }
            return;
        }
        k = k/2;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                long ans = cal(i,j,k);
                out.print((2*ans)+" ");
            }
            out.println();
        }
    }
    static long cal(int i, int j,int k){
        if(k==0)return 0;
        if(dp[i][j][k]!=null)return dp[i][j][k];
        long ans = ded;
        for(int h = 0; h < 4; h++){
            int ni = i+di[h];
            int nj = j+dj[h];
            if(e(ni,nj)){
                int cost = 0;
                if(ni==i){
                    if(nj>j){
                        cost = hor[i][j];
                    }else{
                        cost = hor[i][nj];
                    }
                }if(nj==j){
                    if(ni>i){
                        cost = ver[i][j];
                    }else{
                        cost = ver[ni][j];
                    }
                }
                ans = Math.min(ans,(cost)+cal(ni,nj,k-1));
            }
        }
        return dp[i][j][k] =  ans;
    }
    static int[] di = new int[]{0,-1,0,1};
    static int[] dj = new int[]{-1,0,1,0};
    static boolean e(int i, int j){
        return i>=0&&j>=0&&i<n&&j<m;
    }
    static class Pair implements Comparable<Pair> {
        int x;
        int y;
        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
        @Override
        public int compareTo(Pair o){
            return this.x-o.x;
        }

        @Override
        public String toString() {
            return "Pair{" + "x=" + x + ", y=" + y + '}';
        }

        public boolean equals(Pair o){
            return this.x==o.x&&this.y==o.y;
        }
    }
    public static long mul(long a, long b) {
        return ((a % MOD) * (b % MOD)) % MOD;
    }
    public static long add(long a, long b) {
        return ((a % MOD) + (b % MOD)) % MOD;
    }
    public static long c2(long n) {
        if ((n & 1) == 0) {
            return mul(n / 2, n - 1);
        } else {
            return mul(n, (n - 1) / 2);
        }
    }
    //Shuffle Sort
    static final Random random = new Random();
    static void ruffleSort(int[] a) {
        int n = a.length;//shuffle, then sort
        for (int i = 0; i < n; i++) {
            int oi = random.nextInt(n); int temp= a[oi];
            a[oi] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }
    //Brian Kernighans Algorithm
    static long countSetBits(long n) {
        if (n == 0) return 0;
        return 1 + countSetBits(n & (n - 1));
    }
    //Euclidean Algorithm
    static long gcd(long A, long B) {
        if (B == 0) return A;
        return gcd(B, A % B);
    }
    //Modular Exponentiation
    static long fastExpo(long x, long n) {
        if (n == 0) return 1;
        if ((n & 1) == 0) return fastExpo((x * x) % MOD, n / 2) % MOD;
        return ((x % MOD) * fastExpo((x * x) % MOD, (n - 1) / 2)) % MOD;
    }
    //AKS Algorithm
    static boolean isPrime(long n) {
        if (n <= 1) return false;
        if (n <= 3) return true;
        if (n % 2 == 0 || n % 3 == 0) return false;
        for (int i = 5; i <= Math.sqrt(n); i += 6)
            if (n % i == 0 || n % (i + 2) == 0) return false;
        return true;
    }
    public static long modinv(long x) {
        return modpow(x, MOD - 2);
    }
    public static long modpow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        long x = modpow(a, b / 2);
        x = (x * x) % MOD;
        if (b % 2 == 1) {
            return (x * a) % MOD;
        }
        return x;
    }

    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.*;

public class D7182 {
    public static void main(String[] args) throws IOException {
        init_io();
        int N = nint(), M = nint(), K = nint();
        if (K % 2 == 0) {
            int[][][] grid = new int[K+1][N][M];
            int[][][] edges = new int[4][N][M];
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M-1; j++) {
                    edges[0][i][j] = edges[2][i][j+1] = nint();
                }
            }
            for (int i = 0; i < N-1; i++) {
                for (int j = 0; j < M; j++) {
                    edges[1][i][j] = edges[3][i+1][j] = nint();
                }
            }
            for (int k = 1; k <= K/2; k++) {
                for (int i = 0; i < N; i++) {
                    for (int j = 0; j < M; j++) {
                        int min = Integer.MAX_VALUE;
                        if (i != N-1) {
                            min = Math.min(min, grid[k-1][i+1][j] + edges[1][i][j]);
                        }
                        if (j != M-1) {
                            min = Math.min(min, grid[k-1][i][j+1] + edges[0][i][j]);
                        }
                        if (i != 0) {
                            min = Math.min(min, grid[k-1][i-1][j] + edges[3][i][j]);
                        }
                        if (j != 0) {
                            min = Math.min(min, grid[k-1][i][j-1] + edges[2][i][j]);
                        }
                        grid[k][i][j] = min;
                    }
                }
            }
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    out.print(grid[K/2][i][j]*2 + " ");
                }
                out.println();
            }
        }
        else {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    out.print(-1 + " ");
                }
                out.println();
            }
        }
        out.close();
    }

    static StreamTokenizer in;
    static PrintWriter out;
    static BufferedReader br;

    static int nint() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static void init_io() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        in = new StreamTokenizer(br);
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    }
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static int n;
    public static int m;
    public static int k;
    public static int[][] right;
    public static int[][] down;
    public static int[][][] dp;
    public static void recur(int i, int j, int depth)
    {
        if(dp[i][j][depth]!=-1)
            return;
        int min=Integer.MAX_VALUE;
        // left
        if(j>0)
        {
            recur(i, j-1, depth-1);
            min=Math.min(min, dp[i][j-1][depth-1] + right[i][j-1]);
        }
        // right
        if(j<m-1)
        {
            recur(i, j+1, depth-1);
            min=Math.min(min, dp[i][j+1][depth-1] + right[i][j]);
        }
        // up
        if(i>0)
        {
            recur(i-1, j, depth-1);
            min=Math.min(min, dp[i-1][j][depth-1] + down[i-1][j]);
        }
        // down
        if(i<n-1)
        {
            recur(i+1, j, depth-1);
            min=Math.min(min, dp[i+1][j][depth-1] + down[i][j]);

        }
        dp[i][j][depth]=min;
    }
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        k=sc.nextInt();
        right=new int[n][m-1];
        down=new int[n-1][m];
        for(int i=0;i<n;i++)
            for(int j=0;j<m-1;j++)
                right[i][j]=sc.nextInt();
        for(int i=0;i<n-1;i++)
            for(int j=0;j<m;j++)
                down[i][j]=sc.nextInt();
        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();
            }
        }
        else
        {
            k/=2;
            dp=new int[n][m][k+1];
            for(int i=0;i<n;++i)
                for(int j=0;j<m;j++)
                    for(int z=1;z<=k;z++)
                        dp[i][j][z]=-1;
            for(int i=0;i<n;++i)
                for(int j=0;j<m;j++)
                    recur(i,j,k);
            for(int i=0;i<n;++i) {
                for (int j = 0; j < m; j++)
                    System.out.print((dp[i][j][k] * 2) + " ");
                System.out.println();
            }
        }
    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int t = sc.nextInt();
    for (int tc = 0; tc < t; ++tc) {
      int n = sc.nextInt();
      int[] a = new int[n];
      for (int i = 0; i < a.length; ++i) {
        a[i] = sc.nextInt();
      }

      System.out.println(solve(a));
    }

    sc.close();
  }

  static String solve(int[] a) {
    List<String> result = new ArrayList<>();
    Stack<Integer> stack = new Stack<>();
    for (int ai : a) {
      if (ai != 1) {
        while (stack.peek() + 1 != ai) {
          stack.pop();
        }

        stack.pop();
      }
      stack.push(ai);

      result.add(stack.stream().map(String::valueOf).collect(Collectors.joining(".")));
    }

    return String.join("\n", result);
  }
}


//I'm Whiplash99
import java.io.*;
import java.util.*;
public class C
{
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        int T=Integer.parseInt(br.readLine().trim());
        StringBuilder sb=new StringBuilder();

        while (T-->0)
        {
            N=Integer.parseInt(br.readLine().trim());

            int[] a=new int[N];
            for(i=0;i<N;i++) a[i]=Integer.parseInt(br.readLine().trim());

            int end=1;
            int[][] ans=new int[N][N+10];

            ans[0][0]=1;
            for(i=1;i<N;i++)
            {
                while (true)
                {
                    if(ans[i-1][end]==a[i]-1) break;
                    end--;
                }
                for(int j=0;j<end;j++) ans[i][j]=ans[i-1][j];

                ans[i][end]=a[i];
                end++;
            }

            for(i=0;i<N;i++)
            {
                for(int j=0;j<N&&ans[i][j]!=0;j++)
                {
                    sb.append(ans[i][j]);
                    if(ans[i][j+1]!=0) sb.append('.');
                }
                sb.append("\n");
            }
        }
        System.out.println(sb);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class C {
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter pw;

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

    static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() {
        return Long.parseLong(nextToken());
    }

    static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    static String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        solve();
        pw.close();
    }

    private static void solve() {
        int t = nextInt();
        int[] stack = new int[1000000];
        for (int i = 0; i < t; i++) {
            int n = nextInt();
            stack[0] = nextInt();
            int id = 1;
            pp(stack, id);
            for (int j = 1; j < n; j++) {
                int x = nextInt();
                if (x == 1) {
                    stack[id++] = x;
                } else {
                    while (true) {
                        int p = stack[--id];
                        if (p + 1 == x) {
                            stack[id++] = x;
                            break;
                        }
                    }
                }
                pp(stack, id);
            }
        }
    }

    private static void pp(int[] stack, int size) {
        for (int i = 0; i < size - 1; i++) {
            pw.print(stack[i] + ".");
        }
        pw.println(stack[size - 1]);
    }

}


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

/*
polyakoff
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 1e9 + 10;
    static final long OO = (long) 1e18 + 10;
    static final int MOD = (int) 1e9 + 7;

    static void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        Stack<Integer> st = new Stack<>();
        for (int i = 0; i < n; i++) {
            if (a[i] != 1) {
                while (!st.empty() && st.peek() + 1 != a[i])
                    st.pop();
                st.pop();
            }
            st.push(a[i]);
            for (int j = 0; j < st.size(); j++) {
                out.print(st.get(j));
                if (j < st.size() - 1)
                    out.print('.');
            }
            out.println();
        }

    }

    public static void main(String[] args) {
        in = new FastReader();
        out = new PrintWriter(System.out);

        int t = 1;
        t = in.nextInt();
        while (t-- > 0) {
            solve();
        }

        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader() {
            this(System.in);
        }
        FastReader(String file) throws FileNotFoundException {
            this(new FileInputStream(file));
        }
        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }
        String nextLine() {
            String line;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

import java.lang.*;

public class Practice {
	public static long mod = (long) Math.pow(10, 9) + 7;
	public static long tt = 0;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		int c = 1;
		int t = Integer.parseInt(br.readLine());

		while (t-- > 0) {
			int n = Integer.parseInt(br.readLine());
			HashMap<Integer, Integer> map = new HashMap<>();
			// map.put(1, 0);
			int curr = 0;
			for (int i = 0; i < n; i++) {
				int tt = Integer.parseInt(br.readLine());
				if (tt == 1) {
					curr++;
					map.put(curr, 1);
				} else {
					ArrayList<Integer> list = new ArrayList<Integer>(map.keySet());
					Collections.sort(list);
					for (int a = list.size() - 1; a >= 0; a--) {
						if (map.get(list.get(a)) == tt - 1) {
							map.put(list.get(a), tt);
							break;
						} else {
							curr--;
							map.remove(list.get(a));
						}
					}
				}
				ArrayList<Integer> list = new ArrayList<Integer>(map.keySet());
				Collections.sort(list);
				StringBuilder str=new StringBuilder();
				for(int a=0;a<list.size();a++) {
					if(list.size()-1==a) {
						str.append(map.get(list.get(a)));
						continue;
					}
					str.append(map.get(list.get(a))+".");
				}pw.println(str);

			}

		}
		pw.close();
	}

//	private static long getGCD(long l, long m) {
//		// TODO Auto-generated method stub
//
//		long t1 = Math.min(l, m);
//		long t2 = Math.max(l, m);
//		while (true) {
//			long temp = t2 % t1;
//			if (temp == 0) {
//				return t1;
//			}
//			t2 = t1;
//			t1 = temp;
//		}
//	}
}


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=input.nextInt();
        while(T-->0)
        {
            int n=input.nextInt();
            int b[]=new int[n];
            for(int i=0;i<n;i++)
            {
                b[i]=input.nextInt();
            }
            StringBuilder sb=new StringBuilder("");
            int arr[]=new int[n+1];
            out.println('1');
            sb.append('1');
            int size=1;
            arr[size-1]=1;
            for(int i=1;i<n;i++)
            {
                int a=b[i];
                if(a==1)
                {
                    size++;
                    arr[size-1]=1;
                    sb.append(".1");
                    out.println(sb.toString());
                }
                else
                {
                    sb=new StringBuilder("");
                    int in=0;
                    for(int j=size-1;j>=0;j--)
                    {
                        if(arr[j]==a-1)
                        {
                            in=j;
                            break;
                        }
                    }
                    for(int j=0;j<in;j++)
                    {
                        sb.append(arr[j]+".");
                    }
                    sb.append(a);
                    size=in+1;
                    arr[size-1]=a;
                    out.println(sb.toString());
                }
            }
        }
        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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solve(in, out);
        out.close();
    }

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

    static void sieveOfEratosthenes(int n, int factors[], ArrayList<Integer> ar)
    {
        factors[1]=1;
        int p;
        for(p = 2; p*p <=n; p++)
        {
            if(factors[p] == 0)
            {
                ar.add(p);
                factors[p]=p;
                for(int i = p*p; i <= n; i += p)
                    factors[i] = p;
            }
        }
        for(;p<=n;p++){
            if(factors[p] == 0)
            {
                ar.add(p);
            }
        }
    }

    static void sort(int ar[]) {
        int n = ar.length;
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++)
            a.add(ar[i]);
        Collections.sort(a);
        for (int i = 0; i < n; i++)
            ar[i] = a.get(i);
    }

    static void sort1(long ar[]) {
        int n = ar.length;
        ArrayList<Long> a = new ArrayList<>();
        for (int i = 0; i < n; i++)
            a.add(ar[i]);
        Collections.sort(a);
        for (int i = 0; i < n; i++)
            ar[i] = a.get(i);
    }

    static long ncr(long n, long r, long mod) {
        if (r == 0)
            return 1;
        long val = ncr(n - 1, r - 1, mod);
        val = (n * val) % mod;
        val = (val * modInverse(r, mod)) % mod;
        return val;
    }

    static int findMax(int a[], int n, int vis[], int i, int d){
        if(i>=n)
            return 0;
        if(vis[i]==1)
            return findMax(a, n, vis, i+1, d);
        int max = 0;
        for(int j=i+1;j<n;j++){
            if(Math.abs(a[i]-a[j])>d||vis[j]==1)
                continue;
            vis[j] = 1;
            max = Math.max(max, 1 + findMax(a, n, vis, i+1, d));
            vis[j] = 0;
        }
        return max;
    }

    public static void solve(InputReader sc, PrintWriter pw){
        int i, j = 0;
        // int t = 1;
        int t = sc.nextInt();
        u: while (t-- > 0) {
            int n = sc.nextInt();
            int a[] = new int[n];
            ArrayList<Integer> ar = new ArrayList<>();
            ar.add(0);
            for(i=0;i<1000;i++){
                ar.add(0);
            }
            int m = 1;
            for(i=0;i<n;i++){
                a[i] = sc.nextInt();
                if(a[i]==1){
                    ar.set(m,1);
                    m++;
                }
                else{
                    while(m>0&&ar.get(m-1)!=a[i]-1){
                        m--;
                    }
                    ar.set(m-1,a[i]);
                }
                pw.print(ar.get(1));
                for(j=2;j<m;j++){
                    pw.print("."+ar.get(j));
                }
                pw.println();
            }
        }
    }

    static long findOne(int n, int sz[], ArrayList<Integer> ar){
        long paths = n-1;
        long till = 0;
        for(int v:ar){
            paths += till*sz[v];
            till += sz[v];
        }
        return paths;
    }

    static void assignAnc(ArrayList<Integer> ar[],int sz[], int pa[] ,int curr, int par){
        sz[curr] = 1;
        pa[curr] = par;
        for(int v:ar[curr]){
            if(par==v)
                continue;
            assignAnc(ar, sz, pa, v, curr);
            sz[curr] += sz[v];
        }
    }

    static int findLCA(int a, int b, int par[][], int depth[]){
        if(depth[a]>depth[b]){
            a = a^b;
            b = a^b;
            a = a^b;
        }
        int diff = depth[b] - depth[a];
        for(int i=19;i>=0;i--){
            if((diff&(1<<i))>0){
                b = par[b][i];
            }
        }
        if(a==b)
            return a;
        for(int i=19;i>=0;i--){
            if(par[b][i]!=par[a][i]){
                b = par[b][i];
                a = par[a][i];
            }
        }
        return par[a][0];
    }

    static void formArrayForBinaryLifting(int n, int par[][]){
        for(int j=1;j<20;j++){
            for(int i=0;i<n;i++){
                if(par[i][j-1]==-1)
                    continue;
                par[i][j] = par[par[i][j-1]][j-1];
            }
        }
    }

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

    static class Pair1 {
        long a;
        long b;

        Pair1(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }

    static class Pair implements Comparable<Pair> {
        int a;
        int b;
        int c;

        Pair(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

        public int compareTo(Pair p) {
            // if(a!=p.a)
            //     return a-p.a;
            // return b-p.b;
            return p.c - c;
        }
    }

    // static boolean isPrime(long n) {
    //     if (n <= 1)
    //         return false;
    //     if (n <= 999)
    //         return true;
    //     if (n % 2 == 0 || n % 999 == 0)
    //         return false;
    //     for (int i = 5; i * i <= n; i = i + 6)
    //         if (n % i == 0 || n % (i + 2) == 0)
    //             return false;
    //     return true;
    // }

    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    static long fast_pow(long base, long n, long M) {
        if (n == 0)
            return 1;
        if (n == 1)
            return base % M;
        long halfn = fast_pow(base, n / 2, M);
        if (n % 2 == 0)
            return (halfn * halfn) % M;
        else
            return (((halfn * halfn) % M) * base) % M;
    }

    static long modInverse(long n, long M) {
        return fast_pow(n, M - 2, M);
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 9992768);
            tokenizer = null;
        }

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

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

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int tests = in.nextInt();

            for (int t = 0; t < tests; t++) {
                int numLines = in.nextInt();
                // greedy, maintain stack, keep stack as big as possible
                int stackIdx = -1;
                int[] stack = new int[10000];
                String prev = "";
                for (int x = 0; x < numLines; x++) {
                    int depth = 0;
                    int next = in.nextInt();
                    boolean found = false;
                    for (int i = stackIdx; i >= 0; i--) {
                        if (next == stack[i] + 1) {
                            depth = i;
                            found = true;
                            break;
                        }
                    }
                    if (found == true) {
                        stackIdx = depth;
                        stack[depth] = next;
                        for (int i = 0; i <= depth; i++) {
                            if (i != 0) {
                                out.print(".");
                            }
                            out.print(stack[i]);
                        }
                        out.println();

                    } else if (next == 1) {
                        stackIdx++;
                        stack[stackIdx] = 1;
                        for (int i = 0; i <= stackIdx; i++) {
                            if (i != 0) {
                                out.print(".");
                            }
                            out.print(stack[i]);
                        }
                        out.println();

                    } else {
                        // start a new one
                        stackIdx = 0;
                        stack[0] = next;
                        out.println(next);
                    }

                }
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

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

        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) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

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

        }

    }
}


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

public class C {
    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;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static long gcd(long a,long b)
    {
        if(b==0)
        {
            return a;
        }
        return gcd(b,a%b);
    }

    static int gcd(int a,int b)
    {
        if(b==0)
        {
            return a;
        }
        return gcd(b,a%b);
    }

    static boolean isPrime(int n) {
        //check if n is a multiple of 2
        if (n % 2 == 0) return false;
        //if not, then just check the odds
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            if (n % i == 0)
                return false;
        }
        return true;
    }
    static int MOD=1000000007;

    static long mpow(long base,long pow)
    {
        long res=1;
        while(pow>0)
        {
            if(pow%2==1)
            {
                res=(res*base)%MOD;
            }
            pow>>=1;
            base=(base*base)%MOD;
        }
        return res;
    }

    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        int t = ri();
//        int t = 1;
        while (t-- > 0)
        {
            int n=ri();
            int[] arr=rai(n);

            List<Integer> list = new ArrayList<>();
            for(int i:arr)
            {
                if(i==1)
                {
                    list.add(i);
                }
                else
                {
                    int ind = list.size()-1;
                    while(list.size()>0 && list.get(ind)+1!=i )
                    {
                        list.remove(list.size()-1);
                        ind=list.size()-1;
                    }
                    if(list.size()>0)
                    {
                        list.remove(list.size()-1);
                    }
                    list.add(i);
                }

                for(int j=0;j<list.size()-1;j++)
                {
                    ans.append(list.get(j)).append(".");
                }
                ans.append(list.get(list.size()-1)).append("\n");
            }
        }
        out.print(ans.toString());
        out.flush();
    }

}


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

public class C1523 {
	public static void print(Stack<Integer> st, PrintWriter pw) {
		for (int i = 0; i < st.size(); i++) {
			pw.print(st.get(i));
			if (i != st.size() - 1) {
				pw.print(".");
			}
		}
		pw.println();
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			int[] arr = sc.nextIntArr(n);
			Stack<Integer> st = new Stack<Integer>();
			st.add(arr[0]);
			print(st, pw);
			for (int i = 1; i < n; i++) {
				if (arr[i] == 1) {
					st.add(arr[i]);
				} else {
					while (st.peek() != arr[i] - 1) {
						st.pop();
					}
					st.pop();
					st.add(arr[i]);
				}
				print(st, pw);
			}
		}
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader f) {
			br = new BufferedReader(f);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

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

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = Integer.parseInt(next());
			}
			return arr;
		}

	}

}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		for(int q=0;q<t;q++){
		      String s = br.readLine();
		      int n = Integer.parseInt(s);
		      int a[] = new int[1000];
		      int index=0;
		      for(int i=0;i<n;i++){
		            int x = Integer.parseInt(br.readLine());
		            for(int j=index;j>=0;j--){
		                  if(x-1==a[j]){
		                        a[j]=x;

		                  for(int k=0;k<j;k++){
		                        System.out.print(a[k]+".");
		                  }
		                  System.out.print(a[j]);
		                  System.out.println();
		                  for(int k=j+1;k<1000;k++){
		                        if(a[k]!=0)
		                        a[k]=0;
		                        else
		                        break;
		                  }
		                  index=j+1;
		                //  System.out.println(a[j]+"*"+j);
		                  break;
		                  }
		            }
		      }
		}
	}
}


import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Random;
import java.io.FileWriter;
import java.io.PrintWriter;
/*
    Solution Created: 19:12:30 30/05/2021
    Custom Competitive programming helper.
*/

public class Main {
	public static void solve() {
		int n = in.nextInt();
		ArrayList<Integer> ans = new ArrayList<>();
		out.println(in.nextInt());
		ans.add(1);
		for(int i = 0; i<n-1; i++) {
			int cur = in.nextInt();
			if(ans.isEmpty() || cur==1) ans.add(cur);
			else {
				while((!ans.isEmpty()) && (ans.get(ans.size()-1)+1!=cur)) ans.remove(ans.size()-1);
				if(!ans.isEmpty()) ans.remove(ans.size()-1);
				ans.add(cur);
			}
			int cnt = 0;
			for(int j : ans) {
				cnt++;
				out.print(j+(cnt==ans.size()?"":"."));
			}
			out.println();
		}

	}
	static boolean equal(ArrayList<Integer> a, ArrayList<Integer> b) {
		if(a.size()!=b.size()) return false;
		for(int i = 0; i<a.size(); i++) if(a.get(i)!=b.get(i)) return false;
		return true;
	}

	public static void main(String[] args) {
		in = new Reader();
		out = new Writer();
		int t = in.nextInt();
		while(t-->0) solve();
		out.exit();
	}
	static Reader in; static Writer out;

static class Reader {
	static BufferedReader br;
	static StringTokenizer st;

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

	public Reader(String f){
		try {
			this.br = new BufferedReader(new FileReader(f));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

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

	public double[] nd(int n) {
		double[] a = new double[n];
		for (int i = 0; i < n; i++) a[i] = nextDouble();
		return a;
	}

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

	public char[] nca() {
		return next().toCharArray();
	}

	public String[] ns(int n) {
		String[] a = new String[n];
		for (int i = 0; i < n; i++) a[i] = next();
		return a;
	}

	public int nextInt() {
		ensureNext();
		return Integer.parseInt(st.nextToken());
	}

	public double nextDouble() {
		ensureNext();
		return Double.parseDouble(st.nextToken());
	}

	public Long nextLong() {
		ensureNext();
		return Long.parseLong(st.nextToken());
	}

	public String next() {
		ensureNext();
		return st.nextToken();
	}

	public String nextLine() {
		try {
			return br.readLine();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	private void ensureNext() {
		if (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

static class Util{
		private static Random random = new Random();
		static long[] fact;

		public static void initFactorial(int n, long mod) {
			fact = new long[n+1];
			fact[0] = 1;
			for (int i = 1; i < n+1; i++) fact[i] = (fact[i - 1] * i) % mod;
		}

		public static long modInverse(long a, long MOD) {
			long[] gcdE = gcdExtended(a, MOD);
			if (gcdE[0] != 1) return -1; // Inverted doesn't exist
			long x = gcdE[1];
			return (x % MOD + MOD) % MOD;
		}

		public static long[] gcdExtended(long p, long q) {
			if (q == 0) return new long[] { p, 1, 0 };
			long[] vals = gcdExtended(q, p % q);
			long tmp = vals[2];
			vals[2] = vals[1] - (p / q) * vals[2];
			vals[1] = tmp;
			return vals;
		}

		public static long nCr(int n, int r, long MOD) {
			if (r == 0) return 1;
			return (fact[n] * modInverse(fact[r], MOD) % MOD * modInverse(fact[n - r], MOD) % MOD) % MOD;
		}

		public static long nCr(int n, int r) {
			return (fact[n]/fact[r])/fact[n-r];
		}

		public static long nPr(int n, int r, long MOD) {
			if (r == 0) return 1;
			return (fact[n] * modInverse(fact[n - r], MOD) % MOD) % MOD;
		}
		public static long nPr(int n, int r) {
			return fact[n]/fact[n-r];
		}

		public static boolean isPrime(int n) {
	        if (n <= 1) return false;
	        if (n <= 3) return true;
	        if (n % 2 == 0 || n % 3 == 0) return false;
	        for (int i = 5; i * i <= n; i = i + 6)
	            if (n % i == 0 || n % (i + 2) == 0)
	            return false;
	        return true;
	    }

	    public static boolean[] getSieve(int n) {
	        boolean[] isPrime = new boolean[n+1];
	        for (int i = 2; i <= n; i++) isPrime[i] = true;
	        for (int i = 2; i*i <= n; i++) if (isPrime[i])
	                for (int j = i; i*j <= n; j++) isPrime[i*j] = false;
	        return isPrime;
	    }

	    public static int gcd(int a, int b) {
	    	int tmp = 0;
	    	while(b != 0) {
	    		tmp = b;
	    		b = a%b;
	    		a = tmp;
	    	}
	    	return a;
	    }

	    public static long gcd(long a, long b) {
	    	long tmp = 0;
	    	while(b != 0) {
	    		tmp = b;
	    		b = a%b;
	    		a = tmp;
	    	}
	    	return a;
	    }

	    public static int random(int min, int max) {
	    	return random.nextInt(max-min+1)+min;
	    }

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

		public static void reverse(int[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				int tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }

		public static void reverse(int[] s) {
			reverse(s, 0, s.length-1);
	    }

		public static void reverse(long[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				long tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }

		public static void reverse(long[] s) {
			reverse(s, 0, s.length-1);
	    }

		public static void reverse(float[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				float tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }

		public static void reverse(float[] s) {
			reverse(s, 0, s.length-1);
	    }

		public static void reverse(double[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				double tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }

		public static void reverse(double[] s) {
			reverse(s, 0, s.length-1);
	    }

		public static void reverse(char[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				char tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }

		public static void reverse(char[] s) {
			reverse(s, 0, s.length-1);
	    }

		public static <T> void reverse(T[] s, int l , int r) {
			for(int i = l; i<=(l+r)/2; i++) {
				T tmp = s[i];
				s[i] = s[r+l-i];
				s[r+l-i] = tmp;
			}
	    }

		public static <T> void reverse(T[] s) {
			reverse(s, 0, s.length-1);
	    }

		public static void shuffle(int[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            int t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }

	    public static void shuffle(long[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            long t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }

	    public static void shuffle(float[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            float t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }

	    public static void shuffle(double[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            double t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }

	    public static void shuffle(char[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            char t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }

	    public static <T> void shuffle(T[] s) {
	        for (int i = 0; i < s.length; ++i) {
	            int j = random.nextInt(i + 1);
	            T t = s[i];
	            s[i] = s[j];
	            s[j] = t;
	        }
	    }

		public static void sortArray(int[] a) {
	        shuffle(a);
	        Arrays.sort(a);
	    }

		public static void sortArray(long[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }

		public static void sortArray(float[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }

		public static void sortArray(double[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }

		public static void sortArray(char[] a) {
			shuffle(a);
	        Arrays.sort(a);
	    }

		public static <T extends Comparable<T>> void sortArray(T[] a) {
	        Arrays.sort(a);
	    }
	}

static class Writer {
	private PrintWriter pw;
	public Writer(){
		pw = new PrintWriter(System.out);
	}

	public Writer(String f){
		try {
			pw = new PrintWriter(new FileWriter(f));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void printArray(int[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
	}

	public void printlnArray(int[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
		pw.println();
	}

	public void printArray(long[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
	}

	public void printlnArray(long[] a) {
		for(int i = 0; i<a.length; i++) print(a[i]+" ");
		pw.println();
	}

	public void print(Object o) {
		pw.print(o.toString());
	}

	public void println(Object o) {
		pw.println(o.toString());
	}

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

	public void flush() {
		pw.flush();
	}
	public void exit() {
		pw.close();
	}
}
}


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

public class C {

	static int ar[];
	static HashMap<String, ArrayList<String>> map;
	static int location = 0;
	static StringBuilder sb;
	static int N;

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		int t = Integer.parseInt(br.readLine());

		while(t --> 0) {

			int n = Integer.parseInt(br.readLine());
			ar = new int[n];
			location = 0;
			map = new HashMap<String, ArrayList<String>>();
			sb = new StringBuilder();
			N = n;

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

				ar[i] = Integer.parseInt(br.readLine());

			}

			int idx = 2;
			location = 1;

			sb.append("1\n");

			while(location < n) {

				if(ar[location] == 1) {

					nl((idx-1)+".");

				}else {

					sb.append(idx+"\n");
					idx++;
					location++;

				}

			}

			System.out.println(sb);

		}

	}

	public static void nl(String l) {

		int idx = 1;
		//System.out.println(location + " " + l);

		while(location < N) {

			if(idx == ar[location]) {

				sb.append(l + idx + "\n");
				idx++;
				location++;

			}else if(ar[location] == 1) {

				nl(l + (idx-1) + ".");

			}else {

				return;

			}

		}

	}

}