#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n, m, k, a[104][104], mask[104][104], res[104][104];
int mx[] = {0, 1, 0};
int my[] = {0, 0, 1};
long long ans;
inline bool check(int x, int y, int color) {
  mask[x][y] = (1 << k) - 1;
  for (int i = 1; i <= 2; i++) {
    int tx = x - mx[i];
    int ty = y - my[i];
    if (tx < 1 || ty < 1) continue;
    mask[x][y] &= mask[tx][ty];
  }
  if (mask[x][y] & (1 << (color - 1))) {
    mask[x][y] -= (1 << (color - 1));
    return true;
  }
  return false;
}
inline long long get_ans() {
  int new_col[104];
  memset(new_col, 0, sizeof(new_col));
  bool b[104];
  memset(b, false, sizeof(b));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != 0) {
        if (new_col[res[i][j]] && new_col[res[i][j]] != a[i][j])
          return 0;
        else
          new_col[res[i][j]] = a[i][j];
      }
      b[res[i][j]] = true;
    }
  }
  for (int i = 1; i <= k; i++)
    for (int j = i + 1; j <= k; j++)
      if (new_col[i] && new_col[j] && new_col[i] == new_col[j]) return 0;
  int cnt = 0, s = k;
  for (int i = 1; i <= k; i++) {
    if (new_col[i])
      s--;
    else if (b[i])
      cnt++;
  }
  long long ret = 1;
  for (int i = s; i >= s - cnt + 1; i--) ret = ret * i % mod;
  return ret;
}
long long dfs(int x, int y, int color) {
  long long ret = 0;
  if (x == n + 1) {
    ret = get_ans();
    return ret;
  }
  int tx = x, ty = y;
  if (y == m)
    tx++, ty = 1;
  else
    ty++;
  for (int i = 1; i <= min(color, k); i++) {
    bool f = check(x, y, i);
    if (f) {
      res[x][y] = i;
      int new_col = max(color, i + 1);
      ret += dfs(tx, ty, new_col);
      ret %= mod;
      res[x][y] = 0;
    }
  }
  return ret;
}
int main() {
  cin >> n >> m >> k;
  if (n + m - 1 > k) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  ans = dfs(1, 1, 1);
  cout << ans;
  return 0;
}
