#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 50, INF = 0x3f3f3f3f, mod = 1e9 + 7;
inline int read() {
  register int x = 0, w = 1;
  register char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') w = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * w;
}
inline void write(register int x) {
  if (x / 10) write(x / 10);
  putchar(x % 10 + '0');
}
int n, m, k;
int a[10][10], s[10][10], vis[11];
inline int DFS(register int now, register int ans = 0) {
  if (now == n * m + 1) return 1;
  register int x = (now - 1) / m + 1, y = now % m ? now % m : m,
               S = s[x - 1][y] | s[x][y - 1], cnt = 0;
  for (register int i = 1; i <= k; i++)
    if (1 << i & S) cnt++;
  if (n - x + m - y + 1 > k - cnt) return 0;
  if (a[x][y]) {
    if (1 << a[x][y] & S) return 0;
    vis[a[x][y]]++, s[x][y] = 1 << a[x][y] | S,
                    ans = (ans + DFS(now + 1)) % mod, s[x][y] = 0,
                    vis[a[x][y]]--;
  } else {
    for (register int i = 1, res = -1; i <= k; i++) {
      if (1 << i & S) continue;
      vis[i]++;
      if (vis[i] == 1) {
        if (res == -1) s[x][y] = 1 << i | S, res = DFS(now + 1), s[x][y] = 0;
        ans = (ans + res) % mod;
      } else
        s[x][y] = 1 << i | S, ans = (ans + DFS(now + 1)) % mod, s[x][y] = 0;
      vis[i]--;
    }
  }
  return ans;
}
int main() {
  n = read(), m = read(), k = read();
  if (n + m - 1 > k) return puts("0"), 0;
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= m; j++) a[i][j] = read(), vis[a[i][j]]++;
  printf("%d\n", DFS(1));
  return 0;
}
