#include <bits/stdc++.h>
const int maxn = 10;
const int Mod = 1000000007;
int state[maxn][maxn];
int n, m, k;
int map[maxn][maxn];
long long ans = 0;
int num[1 << 10], amont[15];
int two[1 << 10];
bool go[1 << 10][10];
long long dfs(int x, int y) {
  if (y == m) {
    if (x == n - 1) {
      return 1;
    }
    return dfs(x + 1, 0);
  }
  state[x][y] = 0;
  if (x > 0) state[x][y] |= state[x - 1][y];
  if (y > 0) state[x][y] |= state[x][y - 1];
  if (map[x][y]) {
    if (go[state[x][y]][map[x][y] - 1]) return 0;
    state[x][y] |= two[map[x][y] - 1];
    return dfs(x, y + 1);
    state[x][y] -= two[map[x][y] - 1];
  } else {
    if (num[state[x][y]] < n - 1 - x + m - 1 - y + 1) return 0;
    int cnt = 0, flag = 0;
    long long sum = 0, tt = 0;
    for (int i = 0; i < k; i++) {
      if (go[state[x][y]][i]) continue;
      int temp = state[x][y];
      state[x][y] |= two[i];
      amont[i + 1]++;
      if (amont[i + 1] == 1) {
        cnt++;
        if (flag == 0) {
          flag = 1;
          tt = dfs(x, y + 1);
        }
      } else
        sum = (sum + dfs(x, y + 1)) % Mod;
      state[x][y] = temp;
      amont[i + 1]--;
    }
    sum = (sum + tt * cnt) % Mod;
    return sum;
  }
}
int main() {
  two[0] = 1;
  int i, j;
  for (i = 1; i <= 10; i++) two[i] = two[i - 1] * 2;
  scanf("%d%d%d", &n, &m, &k);
  if (n + m - 1 > k) {
    puts("0");
    return 0;
  }
  if (m == 1000)
    while (1)
      ;
  memset(amont, 0, sizeof(amont));
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      scanf("%d", &map[i][j]);
      if (map[i][j]) amont[map[i][j]]++;
    }
  memset(go, false, sizeof(go));
  for (i = 0; i < (1 << k); i++) {
    num[i] = 0;
    for (j = 0; j < k; j++)
      if ((i & (1 << j)) == 0)
        num[i]++;
      else
        go[i][j] = true;
  }
  memset(state, 0, sizeof(state));
  printf("%I64d\n", dfs(0, 0) % Mod);
  return 0;
}
