#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MAXN = 1005;
char G[MAXN][MAXN], tmp[MAXN][MAXN];
template <typename T>
vector<vector<T>> mmult(const vector<vector<T>>& A, const vector<vector<T>>& B) {
	assert(A[0].size() == B.size());
	int n = A.size(), m = B[0].size(), p = A[0].size();
	vector<vector<T>> C(n, vector<T>(m));
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			for (int k = 0; k < p; ++k)
				C[i][j] += A[i][k] * B[k][j];
	return C;
}
template <typename T>
vector<vector<T>> mexp(vector<vector<T>> A, ll p) {
	assert(A.size() == A[0].size());
	int n = A.size();
	vector<vector<T>> ret = A;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			ret[i][j] = i == j;
	for (; p; p >>= 1, A = mmult(A, A)) if (p & 1) ret = mmult(ret, A);
	return ret;
}
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
int main() {
	int H, W;
	ll K;
	scanf("%d%d%lld", &H, &W, &K);
	int numx = 0;
	for (int i = 0; i < H; ++i) {
		scanf("%s", G[i]);
		for (int j = 0; j < W; ++j) numx += G[i][j] == '#';
	}
	if (K == 0) {
		printf("1\n");
		return 0;
	}
	bool horConn = false, vertConn = false;
	for (int i = 0; i < H; ++i) {
		if (G[i][0] == '#' && G[i][W - 1] == '#') horConn = true;
	}
	for (int i = 0; i < W; ++i) {
		if (G[0][i] == '#' && G[H - 1][i] == '#') vertConn = true;
	}
	if (horConn && vertConn) {
		printf("1\n");
		return 0;
	}
	if (!horConn && !vertConn) {
		printf("%d\n", modex(Mint(numx), K - 1).val);
		return 0;
	}
	if (vertConn) {
		for (int i = 0; i < H; ++i)
			for (int j = 0; j < W; ++j)
				tmp[j][i] = G[i][j];
		memcpy(G, tmp, sizeof(G));
		swap(H, W);
	}
	// Assume horizontally connected now.
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < H; ++i) {
		vector<pair<int, int>> ranges;
		int st = -1;
		for (int j = 0; j < W; ++j) {
			if (G[i][j] == '#') {
				if (st == -1) st = j;
				if (j + 1 == W || G[i][j + 1] == '.') {
					ranges.emplace_back(st, j);
					st = -1;
				}
			}
		}
		if (ranges.empty()) continue;
		if (ranges.size() == 1) {
			if (ranges[0] == make_pair(0, W - 1)) ++a;
			else ++b;
		} else {
			b += ranges.size();
			if (ranges[0].first == 0 && ranges.back().second == W - 1) {
				++c;
				b -= 2;
			}
		}
	}
	vector<vector<Mint>> M = {{a, 0, 0}, {b, numx, numx - a + b}, {c, 0, a + c}};
	auto res = mexp(M, K - 1);
	Mint ans = res[0][0] + res[1][0] + 2 * res[2][0];
	printf("%d\n", ans.val);
}


Measured memory_bytes: 2176