#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, k, cnt, lim;
int a[12][12], mp[12];
struct Hash {
  const static int p = 1333331;
  int tot, head[p], nxt[p], to[p], val[p];
  inline int& operator[](int x) {
    int y = x % p;
    for (int i = head[y]; i; i = nxt[i])
      if (to[i] == x) return val[i];
    nxt[++tot] = head[y];
    to[head[y] = tot] = x;
    return val[tot] = 0;
  }
  inline void clear() {
    memset(head, 0, sizeof(head));
    tot = 0;
  }
} f[2];
inline int get(int st, int k) { return st >> ((k - 1) * 3) & 7; }
inline int turn(int st, int k, int to) {
  return st |= 7 << (k - 1) * 3, st ^= 7 - to << (k - 1) * 3;
}
int s[12];
inline int check(int st) {
  int c = 0;
  for (int i = lim; i <= k; ++i) s[++c] = get(st, i);
  sort(s + 1, s + c + 1);
  for (int i = lim; i <= k; ++i) st = turn(st, i, s[i - lim + 1]);
  return st;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  if (n + m - 1 > k) return puts("0") & 0;
  if (n < m) {
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) scanf("%d", &a[j][i]);
    swap(n, m);
  } else
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] && !mp[a[i][j]]) mp[a[i][j]] = ++cnt;
  lim = cnt + 1;
  for (int i = 1; i <= k; ++i)
    if (!mp[i]) mp[i] = ++cnt;
  int cur = 1;
  f[cur][0] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cur ^= 1;
      f[cur].clear();
      for (int t = 1; t <= f[cur ^ 1].tot; ++t) {
        int st = f[cur ^ 1].to[t], val = f[cur ^ 1].val[t];
        if (a[i][j]) {
          int d = get(st, mp[a[i][j]]);
          if (d && d <= j) continue;
          (f[cur][turn(st, mp[a[i][j]], j)] += val) %= mod;
        } else {
          for (int o = 1; o <= k; ++o) {
            int d = get(st, mp[o]);
            if (d && d <= j) continue;
            (f[cur][check(turn(st, mp[o], j))] += val) %= mod;
          }
        }
      }
    }
  int ans = 0;
  for (int i = 1; i <= f[cur].tot; ++i) (ans += f[cur].val[i]) %= mod;
  printf("%d\n", ans);
  return 0;
}
