#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[20][20], mask[20][20], c[20][20], p[20];
bool f[20];
inline bool check(int x, int y) {
  mask[x][y] = 0;
  if (x != 1) mask[x][y] |= mask[x - 1][y];
  if (y != 1) mask[x][y] |= mask[x][y - 1];
  if (mask[x][y] & (1 << c[x][y])) return false;
  mask[x][y] |= (1 << c[x][y]);
  return true;
}
long long get_ans() {
  long long ans = 1;
  memset(p, -1, sizeof(p));
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      f[c[i][j]] = 1;
      if (a[i][j] == -1) continue;
      if (p[c[i][j]] != -1 && p[c[i][j]] != a[i][j]) return 0ll;
      p[c[i][j]] = a[i][j];
    }
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < i; j++) {
      if (p[i] == p[j] && p[i] != -1) return 0ll;
    }
  }
  int S = k, s = 0;
  for (int i = 0; i < k; i++) {
    if (p[i] != -1) {
      S--;
    } else {
      if (f[i]) s++;
    }
  }
  for (int i = 0; i < s; i++) {
    ans *= (S - i);
    ans %= (1000000007ll);
  }
  return ans;
}
long long dfs(int x, int y, int used) {
  int nx, ny;
  long long ans = 0;
  nx = x;
  ny = y + 1;
  if (ny == m + 1) {
    ny = 1;
    nx = x + 1;
  }
  if (x == n + 1) return get_ans();
  for (int i = 0; i <= used; i++) {
    if (i >= k) break;
    c[x][y] = i;
    if (check(x, y)) {
      ans += dfs(nx, ny, max(used, i + 1));
      if (ans >= (1000000007ll)) ans -= (1000000007ll);
    }
    c[x][y] = -1;
  }
  return ans % (1000000007ll);
}
int main() {
  cin >> n >> m >> k;
  if (n + m > k + 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  long long ans = dfs(1, 1, 0);
  cout << ans;
  return 0;
}
