#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
//#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define INFST (0x7f7f7f7f)
#define INFLLST (0x7f7f7f7f7f7f7f7fll)
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
typedef complex<ld> base;
const ld EPS = (ld)1e-7;
const ld PI = acos(0) * 2;
bool isZero(const ld& x) { return abs(x) <= EPS; }
int sign(const ld& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return abs(a); }
pll operator + (const pll& a, const pll& b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll& a, const pll& b) { return pll(a.first-b.first, a.second-b.second); }
pll operator * (const pll& a, const ll& b) { return pll(a.first*b, a.second*b); }
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }
int rd(int s, int e) { return rand()%(e-s+1) + s; }
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }
void fg(vector<pii> G[], int a, int b, int c) { G[a].pb({b, c}); G[b].pb({a, c}); }

const int MAXH = 1005;
const int MAXW = 1005;
const int MOD = 1000000007;

ll pw(ll n, ll k) {
	ll r = 1; for(n %= MOD; k; k >>= 1) {
		if(k&1) r = r*n % MOD;
		n = n*n % MOD;
	} return r;
}
ll inv(ll n) { return pw(n, MOD-2); }

ll C[11];

char A[MAXH][MAXW];

ll Ans;
int H, W; ll K;
int bcnt, x, y;

int main() {
	scanf("%d%d%lld", &H, &W, &K);
	for(int i = 0; i < H; i++) scanf(" %s", A[i]);

	{
		bool ud = false, lr = false;

		for(int i = 0; i < H; i++)
			lr |= ('#' == A[i][0] && '#' == A[i][W-1]);
		for(int i = 0; i < W; i++)
			ud |= ('#' == A[0][i] && '#' == A[H-1][i]);

		for(int i = 0; i < H; i++) for(int j = 0; j < W; j++)
			bcnt += ('#' == A[i][j]);

		if(!ud && !lr) {
			printf("%lld\n", pw(bcnt, K-1));
			return 0;
		}
		if(ud && lr) {
			puts("1");
			return 0;
		}
		if(lr) {
			for(int i = 0; i < H; i++)
				x += ('#' == A[i][0] && '#' == A[i][W-1]);
			for(int i = 0; i < H; i++) for(int j = 1; j < W; j++)
				y += ('#' == A[i][j-1] && '#' == A[i][j]);
		} else {
			for(int i = 0; i < W; i++)
				x += ('#' == A[0][i] && '#' == A[H-1][i]);
			for(int i = 0; i < W; i++) for(int j = 1; j < H; j++)
				y += ('#' == A[j-1][i] && '#' == A[j][i]);
		}
	}

	if(K < 2) {
		puts("1");
		return 0;
	}
	if(2 == K) {
		printf("%d\n", ((bcnt - y) % MOD + MOD) % MOD);
		return 0;
	}

	K -= 2;

	Ans = ll(bcnt - y) * pw(bcnt, K) % MOD;
	ll t = bcnt * inv(x) % MOD;
	ll k = 0;

	if(1 == t) k = K;
	else k = ((pw(t, K) - 1) % MOD + MOD) % MOD * inv((t - 1) % MOD + MOD) % MOD;
	k = k * pw(x, K) % MOD * y % MOD;

	Ans = ((Ans - k) % MOD + MOD) % MOD;

	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 1280