#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long n, m, tot, ans, x, k, all, MAX, sum;
int bad[22][22][22];
int used[1010], free1[1010], use[1010], cnt[1010];
int board[1010][1010];
int min(long long x, long long y) { return x < y ? x : y; }
void cover(int num, int x, int y, int d) {
  for (int i = 0; i <= x; i++)
    for (int j = 0; j <= y; j++) bad[i][j][num] = d;
  for (int i = x; i < n; i++)
    for (int j = y; j < m; j++) bad[i][j][num] = d;
}
void dfs(int x, int y, int d) {
  if (x == n) {
    int tot = 0;
    int temp = 0;
    int x = all;
    for (int i = 1; i <= k; i++)
      if (free1[i]) tot++;
    if (tot > 0) temp = 1;
    for (int i = 1; i <= tot; i++) {
      temp *= x;
      x--;
    }
    ans += temp;
    ans %= mod;
    return;
  }
  if (board[x][y]) {
    dfs(x, y + 1, d);
    return;
  }
  if (y == m) {
    dfs(x + 1, 0, d);
    return;
  }
  for (int num = 1; num <= k; num++) {
    if (!bad[x][y][num]) {
      for (int a = x; a < n; a++)
        for (int b = y; b < m; b++) bad[a][b][num]++;
      if (!used[num]) free1[num]++;
      use[num]++;
      board[x][y] = num;
      dfs(x, y + 1, k);
      board[x][y] = 0;
      use[num]--;
      if (!used[num]) free1[num]--;
      for (int a = x; a < n; a++)
        for (int b = y; b < m; b++) bad[a][b][num]--;
      if (!used[num] && !use[num]) break;
    }
  }
}
int main() {
  cin >> n >> m >> k;
  if (n + m - 1 > k) {
    cout << 0 << endl;
    return 0;
  }
  int color = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> board[i][j];
      int x = board[i][j];
      if (x) {
        if (!cnt[x]) {
          cnt[x] = ++color;
          board[i][j] = color;
        }
        used[cnt[x]] = 1;
        board[i][j] = cnt[x];
        sum += x != 0;
        if (bad[i][j][cnt[x]]) {
          cout << 0 << endl;
          return 0;
        }
        if (board[i][j]) cover(cnt[x], i, j, 1);
      }
    }
  if (sum == n * m) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 1; i <= k; i++)
    if (used[i]) all++;
  all = k - all;
  dfs(0, 0, 1);
  cout << ans % mod << endl;
  return 0;
}
