#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
  int i;
  for (i = 0; i < rep; i++) p[i] = val;
}
int GETi() {
  int i;
  scanf("%d", &i);
  return i;
}
template <class T>
T sqr(T val) {
  return val * val;
}
int H, W, K, unfixed;
int A[1001][1001];
int UM[11][11];
int V[11][11];
signed long long P[11][11];
signed long long mo = 1000000007;
int count(int nk) {
  int as[11];
  int y, x, nf;
  memset(as, 0, sizeof(as));
  for (y = 0; y < H; y++)
    for (x = 0; x < W; x++)
      if (A[y][x] != 0) {
        if (as[V[y][x]] != 0 && as[V[y][x]] != A[y][x]) return 0;
        as[V[y][x]] = A[y][x];
      }
  for (x = 0; x < nk; x++)
    for (y = x + 1; y < nk; y++)
      if (as[x + 1] && as[y + 1] && as[x + 1] == as[y + 1]) return 0;
  nf = 0;
  for (x = 0; x < nk; x++)
    if (as[x + 1]) nf++;
  return P[K - nf][nk - nf];
}
signed long long dfs(int x, int y, int nk) {
  int i;
  signed long long sum = 0;
  UM[y][x] = 0;
  if (y > 0) UM[y][x] |= UM[y - 1][x];
  if (x > 0) UM[y][x] |= UM[y][x - 1];
  int ny, nx;
  nx = x + 1;
  ny = y - 1;
  if (ny < 0 || nx >= W) {
    nx = 0;
    ny = x + y + 1;
  }
  while (ny >= H) ny--, nx++;
  for (i = 1; i <= min(K, nk + 1); i++) {
    if (UM[y][x] & (1 << i)) continue;
    if (W + H - 1 == K && i != x + y + 1) continue;
    UM[y][x] |= 1 << i;
    V[y][x] = i;
    if (x == W - 1 && y == H - 1)
      sum += count(nk + (i == (nk + 1)));
    else
      sum += dfs(nx, ny, nk + (i == (nk + 1)));
    sum %= mo;
    UM[y][x] ^= 1 << i;
  }
  return sum;
}
void solve() {
  int f, r, i, j, k, l, x, y, tx, ty;
  H = GETi();
  W = GETi();
  K = GETi();
  for (y = 0; y < H; y++)
    for (x = 0; x < W; x++) A[y][x] = GETi();
  if (H + W - 1 > K) {
    printf("0\n");
    return;
  }
  for (x = 0; x <= 10; x++) {
    P[x][0] = 1;
    for (y = 0; y < x; y++) P[x][y + 1] = (P[x][y] * (x - y)) % mo;
  }
  memset(UM, 0, sizeof(UM));
  cout << dfs(0, 0, 0) << endl;
  return;
}
int main(int argc, char** argv) {
  if (argc > 1) freopen(argv[1], "r", stdin);
  solve();
  return 0;
}
