#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);

ll mod_pow(ll x, ll n = mod - 2) {
	ll ret = 1;
	while (n > 0) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}

void to_unique(vector<int> &v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

char mp[1000][1000];
bool b[1000][1000];

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
bool used[2000][2000];
bool bb[2000][2000];
int col[1000][1000];
vector<vector<P>> block;

int h, w;
int loc(int x, int y) {
	if (x < h&&y < w)return 0;
	else if (x < h)return 1;
	else if (y < w)return 2;
	else return 3;
}
void solve() {
	ll k; cin >> h >> w >> k;
	rep(i, h) {
		rep(j, w) {
			cin >> mp[i][j];
			if (mp[i][j] == '#')b[i][j] = true;
		}
	}
	if (k == 0) {
		cout << 1 << endl; return;
	}
	if (h*w == 1) {
		cout << 1 << endl; return;
	}
	rep(i, h)rep(j, w)col[i][j] = -1;
	rep(i, h) {
		rep(j, w) {
			if (!b[i][j])continue;
			if (used[i][j])continue;
			queue<P> q;
			q.push({ i,j });
			used[i][j] = true;
			vector<P> cur; cur.push_back({ i,j });
			while (!q.empty()) {
				P p = q.front(); q.pop();
				rep(k, 4) {
					int nx = p.first + dx[k];
					int ny = p.second + dy[k];
					if (nx < 0 || ny < 0 || nx == h || ny == w)continue;
					if (used[nx][ny] || !b[nx][ny])continue;
					used[nx][ny] = true; cur.push_back({ nx,ny });
					q.push({ nx,ny });
				}
			}
			rep(k, cur.size()) {
				col[cur[k].first][cur[k].second] = block.size();
			}
			block.push_back(cur);
		}
	}
	if (k == 1) {
		cout << block.size() << endl;
		return;
	}
	bool by = false, bt = false;
	rep(i, h) {
		if (b[i][0] && b[i][w - 1])by = true;
	}
	rep(j, w) {
		if (b[0][j] && b[h - 1][j])bt = true;
	}
	if (by&&bt) {
		cout << 1 << endl; return;
	}
	ll num = 0;
	rep(i, h)rep(j, w)if (b[i][j])num++;
	ll ans = block.size() * mod_pow(num, k - 1) % mod;
	//cout << ans << endl;
	ll cyoko = 0, cw = 0;
	rep(i, h) {
		if (b[i][0] && b[i][w - 1])cw++;
		rep(j, w - 1) {
			if (b[i][j] && b[i][j + 1])cyoko++;
		}
	}
	ll sumw = mod_pow(num, k - 1) - mod_pow(cw, k - 1);
	if (sumw < 0)sumw += mod;
	sumw = sumw * mod_pow(num - cw) % mod;
	sumw = sumw * cyoko%mod;

	ll ctate = 0, ch = 0;
	rep(j, w) {
		if (b[0][j] && b[h - 1][j])ch++;
		rep(i, h - 1) {
			if (b[i][j] && b[i + 1][j])ctate++;
		}
	}
	ll sumh = mod_pow(num, k - 1) - mod_pow(ch, k - 1);
	if (sumh < 0)sumh += mod;
	sumh = sumh * mod_pow(num - ch) % mod;
	sumh = sumh * ctate%mod;

	rep(i, block.size()) {
		vector<int> yoko, tate;
		rep(j, block[i].size()) {
			int x = block[i][j].first;
			int y = block[i][j].second;
			/*if (x == 0 && b[h - 1][y]) {
			tate.push_back(col[h - 1][y]);
			}*/
			if (x == h - 1 && b[0][y]) {
				tate.push_back(col[0][y]);
			}
			/*if (y == 0 && b[x][w - 1]) {
			yoko.push_back(col[x][w - 1]);
			}*/
			if (y == w - 1 && b[x][0]) {
				yoko.push_back(col[x][0]);
			}
		}
		to_unique(yoko); to_unique(tate);
		(ans += 2 * mod - yoko.size() * sumw - tate.size()*sumh) %= mod;
	}
	cout << ans << endl;

}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(50);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
		return 0;
}


Measured memory_bytes: 27880