#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
using namespace std;
const int P = 1e9 + 7;
int n, m, k, nm;
int h[13][13];
long long ans;
int vis[13][13];
int mp[1234];
bool app[20];
inline void che(int x, int y) {
  for (register int i = 1; i <= x; ++i) {
    for (register int j = 1; j <= y; ++j) {
      if (i == x && j == y) continue;
      if (h[i][j] == h[x][y]) {
        puts("0");
        exit(0);
      }
    }
  }
  app[h[x][y]] = true;
}
inline void Mod(long long &num) {
  if (num >= P) num -= P;
  if (num < 0) num += P;
}
void dfs(int x, int y) {
  if (y == m + 1) y = 1, ++x;
  if (x > n) return Mod(++ans), void();
  vis[x][y] = vis[x - 1][y] & vis[x][y - 1];
  int cnt = 0;
  for (register int i = vis[x][y]; i; i -= ((i) & (-i))) ++cnt;
  --cnt;
  if (cnt < nm - x - y) return;
  if (h[x][y]) {
    if (vis[x][y] & (1 << (h[x][y] - 1))) {
      vis[x][y] ^= (1 << (h[x][y] - 1));
      dfs(x, y + 1);
    }
    return;
  }
  long long val = -1;
  int tmp = vis[x][y];
  while (tmp) {
    int tp = ((tmp) & (-tmp));
    if (!app[mp[tp]]) {
      if (~val) {
        Mod(ans += val);
        tmp -= tp;
      } else {
        long long nwans = ans;
        vis[x][y] ^= tp;
        app[mp[tp]] = true;
        dfs(x, y + 1);
        vis[x][y] ^= tp;
        Mod(val = ans - nwans);
        app[mp[tp]] = false;
        tmp -= tp;
      }
    } else {
      vis[x][y] ^= tp;
      dfs(x, y + 1);
      vis[x][y] ^= tp;
      tmp -= tp;
    }
  }
}
int main() {
  read(n);
  read(m);
  read(k);
  nm = n + m;
  if (nm - 1 > k) {
    puts("0");
    return 0;
  }
  for (register int i = 0; i < 10; ++i) mp[1 << i] = i + 1;
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 1; j <= m; ++j) {
      read(h[i][j]);
      if (h[i][j]) che(i, j);
    }
  }
  int All = (1 << k) - 1;
  for (register int i = 1; i <= m; ++i) vis[0][i] = All;
  for (register int i = 0; i <= n; ++i) vis[i][0] = All;
  dfs(1, 1);
  printf("%lld\n", ans);
  return 0;
}
