//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 1e3 +100, OO = 1e9, T = 10, M = 1e9 + 7, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
char mat[N][N], mat2[N][N];

int pw(int x, int y) {
	if(y == 0)
		return 1;
	int cnt = pw((x * x) % M, y / 2);
	if(y % 2)
		cnt = (cnt * x) % M;
	return cnt;
}


//******************************************matrix.begin()****************************************************
//************************************************************************************************************

struct matrix {
	int a[T][T], n, m;
	matrix (){

	}
	matrix (int n, int m) {
		this->n = n;
		this->m = m;
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				a[i][j] = 0;
	}
	void identity() {
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				a[i][j] = 0;
		for(int i = 0; i < n; i++)
			a[i][i] = 1;
	}
	int* operator[](int x) {
		return a[x];
	}
	matrix operator*(matrix b) {
		matrix c(n, b.m);
		for(int k = 0; k < m; k++)
			for(int i = 0; i < n; i++)
				for(int j = 0; j < b.m; j++)
					c[i][j] = (c[i][j] + (a[i][k] * b[k][j])) % M;
		return c;
	}
	matrix operator^(int k) {
		matrix a = *this;
		matrix t(n, m);
		t.identity();
		while(k) {
			if(k & 1)
				t = t * a;
			k >>= 1;
			a = a * a;
		}
		return t;
	}
};

matrix operator+(matrix &b, matrix &c) {
	matrix t(b.n, b.m);
	for(int i = 0; i < b.n; i++)
		for(int j = 0; j < b.m; j++)
			t[i][j] = (b[i][j] + c[i][j]) % M;
	return t;
}

//************************************************************************************************************
//******************************************matrix.end()******************************************************


int32_t main() {
	use_fast;
	int n, m, k, cnt = 0;
	cin >> n >> m >> k;
	k--;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> mat[i][j];
			if(mat[i][j] == '#')
				cnt++;
		}	
	}
	int v = 0, h = 0;
	for(int i = 1; i <= n; i++) 
		if(mat[i][1] == '#' && mat[i][m] == '#')
			h++;
	for(int i = 1; i <= m; i++) 
		if(mat[1][i] == '#' && mat[n][i] == '#')
			v++;
	if((h && v) || k < 0) 
		return cout << 1, 0;
	if(!h && !v) 
		return cout << pw(cnt, k), 0;
	if(v) {
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
				mat2[j][i] = mat[i][j];
		swap(n, m);
		swap(v, h);
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
				mat[i][j] = mat2[i][j];
	}
	int d = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j < m; j++)
			if(mat[i][j] == mat[i][j+1] && mat[i][j] == '#')
				d++;
	matrix ans(2, 2);
	ans[0][0] = cnt;
	ans[0][1] = -d;
	ans[1][1] = h;
	ans = ans ^ k;
	cout << ((ans[0][0] + ans[0][1]) % M + M) % M << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



Measured memory_bytes: 5692