#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define iter(i, n) for (int i = 1; i <= n; ++i)
#define iter0(i, n) for (int i = 0; i < n; ++i)
#define forw(i, a, b) for (int i = a; i <= b; ++i)
#define NR 1010
const int mod = 1e9 + 7;
typedef long long i64;
typedef pair<int, int> pii;
int n, m;
i64 K;
char s[NR][NR];
bool mp[NR][NR];
int col[NR][NR];
//nwes
/*bool in_grid(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
void dfs(int x, int y) {
col[x][y] = csz;
iter0(d, 4) {
int _x = x + dx[d], _y = y + dy[d];
if (!col[_x][_y]) {
if (in_grid(_x, _y)) dfs(_x, _y);
else {
;
}
}
}
}*/
struct Mat {
int a[2][2];
Mat() { memset(a, 0, sizeof(a)); }
int* operator[](int index) { return a[index]; }
} g;
Mat operator*(Mat a, Mat b) {
Mat c;
iter0(i, 2) iter0(k, 2) iter0(j, 2) c[i][j] = (c[i][j] + 1ll * a[i][k] * b[k][j]) % mod;
return c;
}
Mat pow(Mat a, i64 z) {
Mat s; s[0][0] = s[1][1] = 1;
while (z > 0) {
if (z % 2 == 1) s = s * a;
a = a * a;
z /= 2;
}
return s;
}
int pr(int a, i64 z) {
int s = 1;
while (z > 0) {
if (z % 2 == 1) s = 1ll * s * a % mod;
a = 1ll * a * a % mod;
z /= 2;
}
return s;
}
int main() {
scanf("%d%d%lld", &n, &m, &K);
if (K == 1) { puts("1"); return 0; }
--K;
iter(i, n) {
scanf("%s", s[i] + 1);
iter(j, m) mp[i][j] = (s[i][j] == '#');
}
// iter(i, n) iter(j, m) if (!col[i][j]) { dfs(i, j); break; }
int cx = 0, cy = 0;
iter(i, n) if (mp[i][1] && mp[i][m]) ++cx;
iter(i, m) if (mp[1][i] && mp[n][i]) ++cy;
int c1 = 0;
iter(i, n) iter(j, m) if (mp[i][j]) ++c1;
// printf("%d %d\n", cx, cy);
if (cx != 0 && cy != 0) puts("1");
else if (cx == 0 && cy == 0) printf("%d\n", pr(c1, K));
else {
if (cy != 0) {
iter(i, m) iter(j, n) mp[i][j] = (s[j][i] == '#');
swap(n, m); swap(cx, cy);
}
int c2 = 0;
iter(i, n) iter(j, m) {
if (mp[i][j] && mp[i][j - 1]) ++c2;
}
Mat g; g[0][0] = c1, g[1][0] = mod - c2, g[1][1] = cx;
//printf("%d %d\n", c1, c2);
Mat res = pow(g, K);
printf("%d\n", (res[0][0] + res[1][0]) % mod);
}
/*iter0(s, 4) {
int _s = 0;
int csz = 0;
forw(i, 0, n + 1) forw(j, 0, m + 1) col[i][j] = 0;
iter(sx, n) iter(sy, m) if (!col[sx][sy]) {
int h, t;
q[h = t = 1] = pii(sx, sy);
++csz;
bool vis[4];
while (h <= t) {
pii u = q[h++];
int x = u.fi, y = u.se;
iter0(d, 4) if (s >> (d % 2) & 1) {
int _x = x + dx[d], _y = y + dy[d];
if (col[_x][_y] == 0) {
if (in_grid(_x, _y)) q[++t] = pii(_x, _y), col[_x][_y] = csz;
else {
if (_x < 1) vis[0] = true;
if (_y < 1) vis[1] = true;
if (_x > n) vis[2] = true;
if (_y > m) vis[3] = true;
}
}
}
}
}
}*/
//n * m * c1 - (n-1) * m * c2
return 0;
}