#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int n, m, k;
int buf[1005][1005];
int col[20][20];
int reach[20][20];
const long long int mod = 1000000007;
int match[20], appear[20], rev[20];
long long int calc() {
  memset(rev, -1, sizeof(rev));
  memset(match, -1, sizeof(match));
  memset(appear, 0, sizeof(appear));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) appear[col[i][j]] = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (~buf[i][j]) {
        if (match[buf[i][j]] != -1 && match[buf[i][j]] != col[i][j]) return 0;
        match[buf[i][j]] = col[i][j];
        if (rev[col[i][j]] != -1 && rev[col[i][j]] != buf[i][j]) return 0;
        rev[col[i][j]] = buf[i][j];
      }
  int k2 = 0;
  for (int i = 0; i < k; ++i)
    if (appear[i]) ++k2;
  int emp = 0, cont = 0;
  for (int i = 0; i < k; ++i) {
    if (appear[i] && rev[i] == -1) ++emp;
    if (rev[i] != -1) ++cont;
  }
  long long int ans = 1;
  for (int i = 0; i < emp; ++i) ans *= (k - cont - i);
  ans %= mod;
  return ans;
}
long long int dfs(int y, int x, int used) {
  if (x == m) {
    x = 0;
    ++y;
  }
  if (y == n) return calc();
  long long int res = 0;
  reach[y][x] = ((y > 0 ? reach[y - 1][x] : 0) | (x > 0 ? reach[y][x - 1] : 0));
  for (int i = 0; i < min(used + 1, k); ++i) {
    if (reach[y][x] >> i & 1) continue;
    reach[y][x] |= (1 << i);
    col[y][x] = i;
    res += dfs(y, x + 1, max(used, i + 1));
    if (res >= mod) res -= mod;
    reach[y][x] ^= (1 << i);
  }
  return res;
}
long long int solve() {
  if (n + m - 1 > k) return 0;
  return dfs(0, 0, 0);
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      scanf("%d", &buf[i][j]);
      --buf[i][j];
    }
  cout << solve() << endl;
  return 0;
}
