#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
int inline in() {
  int x = 0, c;
  for (; (unsigned)((c = getchar()) - '0') >= 10;) {
    if (c == '-') return -in();
    if (!~c) throw ~0;
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while ((unsigned)((c = getchar()) - '0') < 10);
  return x;
}
int n, m, k;
int ans;
const int mod = 1e9 + 7;
const int Maxn = 20;
const int Maxk = 12;
int board[Maxn][Maxn], f[Maxk], mp[Maxk];
int bad[Maxn][Maxn];
int calc(int mc) {
  for (int c = 1; c <= k; c++) {
    for (int qc = c + 1; qc <= k; qc++) {
      if (mp[c] != 0 && mp[qc] != 0 && mp[c] == mp[qc]) return 0;
    }
  }
  int free = 0, colors = k;
  for (int i = 1; i <= mc; i++) {
    if (mp[i] == 0)
      free++;
    else
      colors--;
  }
  return f[colors] / f[colors - free];
}
inline bool check(int row, int col, int c) {
  bad[row][col] = 0;
  bad[row][col] = (bad[row - 1][col] | bad[row][col - 1]);
  if (bad[row][col] >> c & 1) return false;
  bad[row][col] |= (1 << c);
  return true;
}
void go(int row, int col, int used) {
  if (row == n + 1) {
    ans = ((long long)ans + calc(used)) % mod;
    return;
  }
  for (int c = 1; c <= k && c <= used + 1; c++) {
    if (check(row, col, c)) {
      bool ok = true;
      if (board[row][col] != 0) {
        if (mp[c] != 0 && mp[c] != board[row][col]) {
          ok = false;
        }
      }
      if (ok) {
        bool flag = false;
        if (mp[c] == 0) {
          mp[c] = board[row][col];
          flag = true;
        }
        if (col == m)
          go(row + 1, 1, max(c, used));
        else
          go(row, col + 1, max(c, used));
        if (flag) {
          mp[c] = 0;
        }
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &board[i][j]);
    }
  }
  f[0] = 1;
  for (int i = 1; i < Maxk; i++) f[i] = f[i - 1] * i;
  go(1, 1, 0);
  printf("%d\n", ans);
  return 0;
}
