template<typename T> inlinevoidread(T &x){ x = 0; T k = 1; char in = getchar(); while (!isdigit(in)) { if (in == '-') k = -1; in = getchar(); } while (isdigit(in)) x = x * 10 + in - '0', in = getchar(); x *= k; }
typedeflonglong ll;
constint MOD = 1e9 + 7; constint N = 805;
int n, m, k; ll ans; int a[N][N], f[N][N][20][2];
inlineintmod(int x){ return (x + k) % k; }
inlinevoidmain(){ read(n), read(m), read(k); k++; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) { read(a[i][j]), a[i][j] %= k; f[i][j][a[i][j]][0] = 1; } for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) for (int x = 0; x < k; ++x) { f[i][j][x][0] = (f[i][j][x][0] + f[i-1][j][mod(x-a[i][j])][1] + f[i][j-1][mod(x-a[i][j])][1]) % MOD; f[i][j][x][1] = (f[i][j][x][1] + f[i-1][j][mod(x+a[i][j])][0] + f[i][j-1][mod(x+a[i][j])][0]) % MOD; } for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) (ans += f[i][j][0][1]) %= MOD; printf("%lld\n", ans); } }