You have a rectangular n × m-cell board. Some cells are already painted some of k colors. You need to paint each uncolored cell one of the k colors so that any path from the upper left square to the lower right one doesn't contain any two cells of the same color. The path can go only along side-adjacent cells and can only go down or right.

Print the number of possible paintings modulo 1000000007 (109 + 7).

Input

The first line contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 10). The next n lines contain m integers each — the board. The first of them contains m uppermost cells of the board from the left to the right and the second one contains m cells from the second uppermost row and so on. If a number in a line equals 0, then the corresponding cell isn't painted. Otherwise, this number represents the initial color of the board cell — an integer from 1 to k.

Consider all colors numbered from 1 to k in some manner.

Output

Print the number of possible paintings modulo 1000000007 (109 + 7).

Examples

Input

2 2 4
0 0
0 0


Output

48


Input

2 2 4
1 2
2 1


Output

0


Input

5 6 10
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0


Output

3628800


Input

2 6 10
1 2 3 4 5 6
0 0 0 0 0 0


Output

4096
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
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);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
	public static final int MODULO = 1000000007;

	class State implements Comparable<State> {
		int mask;
		int ways;

		State(int mask, int ways) {
			this.mask = mask;
			this.ways = ways;
		}

		public int compareTo(State o) {
			return mask - o.mask;
		}
	}

	int n, m, k;
	int[][] a;

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		n = in.nextInt();
		m = in.nextInt();
		k = in.nextInt();
		a = new int[n][];
		for (int i = 0; i < n; ++i) {
			a[i] = in.nextIntArray(m);
		}
		if (n == 1 && m == 1) {
			if (a[0][0] == 0) {
				out.println(k);
			} else {
				out.println(1);
			}
			return;
		}
		boolean bad = false;
		for (int x = 0; x < n; ++x) {
			for (int y = 0; y < m; ++y) {
				if ((x != 0 || y != 0) && a[x][y] == a[0][0] && a[x][y] > 0) {
					bad = true;
				}
				if ((x != n - 1 || y != m - 1) && a[x][y] == a[n - 1][m - 1] && a[x][y] > 0) {
					bad = true;
				}
			}
		}
		if (n + m - 1 > k || bad) {
			out.println(0);
			return;
		}
		if (m > n) {
			int[][] tmp = new int[m][n];
			for (int x = 0; x < n; ++x) {
				for (int y = 0; y < m; ++y) {
					tmp[y][x] = a[x][y];
				}
			}
			a = tmp;
			int sw = n;
			n = m;
			m = sw;
		}
		boolean[] used = new boolean[k];
		for (int x = 0; x < n; ++x) {
			for (int y = 0; y < m; ++y) {
				if (a[x][y] > 0) {
					used[a[x][y] - 1] = true;
				}
			}
		}
		long ansMult = 1;
		if (a[0][0] == 0) {
			ansMult *= useOne(used);
		} else {
			removeColor(a[0][0], used);
		}
		if (a[n - 1][m - 1] == 0) {
			ansMult *= useOne(used);
		} else {
			removeColor(a[n - 1][m - 1], used);
		}
		
		ArrayList <State>[] states = new ArrayList[2];
		//Map<Integer, Integer> other = new HashMap<>();
		states[0] = new ArrayList<>();
		states[1] = new ArrayList<>();
		int old = 0, ne = 1;
		int initMask = 0;
		for (int i = 0; i < k; ++i) {
			initMask = initMask * (m + 1) + m;
		}
		//System.out.println(initMask);
		states[old].add(new State(initMask, 1));
		int[] mult = new int[k];
		mult[0] = 1;
		for (int i = 1; i < k; ++i) {
			mult[i] = mult[i - 1] * (m + 1);
		}
		int[] other = new int[initMask + 1];
		int[] lastSeen = new int[k];
		for (int x = 0; x < n; ++x) {
			for (int y = 0; y < m; ++y) {
				if (x == 0 && y == 0 || x == n - 1 && y == m - 1) {
					continue;
				}
				//other.clear();
				Arrays.fill(other, 0);
				for (State state : states[old]) {
					int mask = state.mask;
					for (int i = 0; i < k; ++i) {
						lastSeen[i] = mask % (m + 1);
						mask /= m + 1;
					}
					int fromLim = 0, toLim = k;
					if (a[x][y] != 0) {
						fromLim = a[x][y] - 1;
						toLim = a[x][y];
					}
					for (int col = fromLim; col < toLim; ++col) {
						if (lastSeen[col] <= y) {
							continue;
						}
						int nMask = state.mask + mult[col] * (y - lastSeen[col]);
						/*Integer val = other.get(nMask);
						if (val == null) {
							other.put(nMask, state.ways);
						} else {
							other.put(nMask, (state.ways + val) % MODULO);
						}*/
						other[nMask] = (other[nMask] + state.ways) % MODULO;
					}
				}
				states[ne].clear();
				/*for (Map.Entry<Integer, Integer> entry : other.entrySet()) {
					states[ne].add(new State(entry.getKey(), entry.getValue()));
				}*/
				for (int mask = 0; mask < other.length; ++mask) {
					if (other[mask] > 0) {
						states[ne].add(new State(mask, other[mask]));
					}
				}
				old ^= 1;
				ne ^= 1;
			}
		}
		int ans = 0;
		for (State state : states[old]) {
			ans = (ans + state.ways) % MODULO;
		}
		out.println((ansMult * ans) % MODULO);
	}

	private int useOne(boolean[] used) {
		int cnt = 0;
		for (int i = 0; i < k; ++i) {
			if (!used[i]) {
				++cnt;
			}
		}
		for (int i = 0; i < k; ++i) {
			if (!used[i]) {
				removeColor(i + 1, used);
				break;
			}
		}
		return cnt;
	}

	private void removeColor(int col, boolean[] used) {
		for (int j = col; j < k; ++j) {
			used[j - 1] = used[j];
		}
		for (int x = 0; x < n; ++x) {
			for (int y = 0; y < m; ++y) {
				if (a[x][y] == col) {
					a[x][y] = -1;
				} else if (a[x][y] > col) {
					--a[x][y];
				}
			}
		}
		--k;
	}
}

class InputReader {
	private final BufferedReader reader;
	private StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		tokenizer = new StringTokenizer("");
	}

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

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

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

	}

class OutputWriter extends PrintWriter {

	public OutputWriter(Writer out) {
		super(out);
	}

	public OutputWriter(OutputStream out) {
		super(out);
	}

	}
