#include <bits/stdc++.h>
using namespace std;
const int N = 25;
const long long mod = 1e9 + 7;
int filled[N][N], a[N][N], b[N][N], n, m, k;
long long count() {
  int par[N];
  bool used[N];
  memset(par, -1, sizeof(par));
  memset(used, false, sizeof(used));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      used[a[i][j]] = true;
      if (filled[i][j] < 0) continue;
      int x = filled[i][j], y = a[i][j];
      if (par[y] > -1 && par[y] != x) return 0;
      par[y] = x;
    }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < i; j++) {
      if (par[i] == par[j] && par[i] != -1) return 0;
    }
  }
  int p = k, q = 0;
  for (int i = 0; i < k; i++) {
    if (par[i] > -1)
      p--;
    else if (used[i])
      q++;
  }
  long long ans = 1;
  while (q--) {
    ans = (ans * p) % mod;
    p--;
  }
  return ans;
}
bool check(int x, int y) {
  b[x][y] = 0;
  if (x) b[x][y] |= b[x - 1][y];
  if (y) b[x][y] |= b[x][y - 1];
  if ((b[x][y] >> a[x][y]) & 1) return false;
  b[x][y] |= 1 << a[x][y];
  return true;
}
long long dfs(int x, int y, int used) {
  if (x == n) return count();
  int nx = x, ny = y + 1;
  if (ny == m) {
    nx++, ny = 0;
  }
  long long ans = 0;
  for (int i = 0; i <= used; i++) {
    if (i >= k) break;
    a[x][y] = i;
    if (check(x, y)) ans += dfs(nx, ny, max(used, i + 1));
    if (ans >= mod) ans -= mod;
  }
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  if (n + m - 1 > k) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &filled[i][j]);
      filled[i][j]--;
    }
  long long ans = dfs(0, 0, 0);
  printf("%d\n", ans);
  return 0;
}
