#include <bits/stdc++.h>
using namespace std;
namespace modular_space {
	long long mod;
	struct umod {
		long long val;
		umod(): val(0ll){}
		umod(long long x){ x %= mod; if(x < 0) x += mod; val = x; }
		umod& operator += (umod oth){ val += oth.val; if(val >= mod) val -= mod; return *this; }
		umod& operator -= (umod oth){ val -= oth.val; if(val < 0) val += mod; return *this; }
		umod& operator *= (umod oth){ val = val * oth.val % mod; return *this; }
		umod& operator /= (umod oth){ return *this *= oth.inverse(); }
		umod& operator ^= (long long oth){ return *this = pwr(*this, oth); }
		umod operator + (umod oth) const { return umod(*this) += oth; }
	       	umod operator - (umod oth) const { return umod(*this) -= oth; }
		umod operator * (umod oth) const { return umod(*this) *= oth; }
		umod operator / (umod oth) const { return umod(*this) /= oth; }
		umod operator ^ (long long oth) const { return umod(*this) ^= oth; }
		bool operator < (umod oth) const { return val < oth.val; }
		bool operator > (umod oth) const { return val > oth.val; }
		bool operator <= (umod oth) const { return val <= oth.val; }
		bool operator >= (umod oth) const { return val >= oth.val; }
		bool operator == (umod oth) const { return val == oth.val; }
		bool operator != (umod oth) const { return val != oth.val; }
		umod pwr(umod a, long long b) const {
			umod r = 1;
			for(; b; a *= a, b >>= 1)
				if(b&1)
					r *= a;
			return r;
		}
		umod inverse() const {
			long long a = val, b = mod, u = 1, v = 0;
			while(b){
				long long t = a/b;
				a -= t * b; swap(a, b);
				u -= t * v; swap(u, v);
			}
			if(u < 0)
				u += mod;
			return u;
		}
		friend istream& operator >> (istream &is, umod &oth);
		friend ostream& operator << (ostream &os, const umod& oth);
	};
	ostream& operator << (ostream &os, const umod &oth){
		os << oth.val;
		return os;
	}
	istream& operator >> (istream &is, umod &oth){
		long long x; is >> x;
		oth = umod(x);
		return is;
	}
	struct binprime_kit {
		int sz;
		vector<umod> fat, ifat;
		void init(int s){
			sz = s;
			fat.resize(sz + 1);
			ifat.resize(sz + 1);
			fat[0] = 1;
			for(int i = 1; i <= sz; i++) fat[i] = fat[i - 1] * i;
			ifat[sz] = fat[sz] ^ (mod - 2);
			for(int i = sz - 1; i >= 0; i--) ifat[i] = ifat[i + 1] * (i + 1);
		}
		umod coef(int n, int r){
			if(n < r) return 0;
			return fat[n] / (ifat[r] * ifat[n - r]);
		}
	};
};
using umod = modular_space::umod;
namespace M{
using T = umod;
const int maxn = 2;
int N = 2; // size to use
// a = 0
void clear(T a[maxn][maxn]){
    for(int e = 0; e < N; e++) for(int f = 0; f < N; f++) a[e][f] = 0;
}
// a = I
void identity(T a[maxn][maxn]){
    for(int e = 0; e < N; e++) for(int f = 0; f < N; f++) a[e][f] = T(e == f);
}
// a = b
void cpy(T a[maxn][maxn], T b[maxn][maxn]){
    for(int e = 0; e < N; e++) for(int f = 0; f < N; f++) a[e][f] = b[e][f];
}
// a = b + c
void add(T a[maxn][maxn], T b[maxn][maxn], T c[maxn][maxn]){
    for(int e = 0; e < N; e++) for(int f = 0; f < N; f++) a[e][f] = b[e][f] + c[e][f];
}
// a = b - c
void sub(T a[maxn][maxn], T b[maxn][maxn], T c[maxn][maxn]){
    for(int e = 0; e < N; e++) for(int f = 0; f < N; f++) a[e][f] = b[e][f] - c[e][f];
}
// a = b * c
void mul(T a[maxn][maxn], T b[maxn][maxn], T c[maxn][maxn]){
    for(int e = 0; e < N; e++) for(int f = 0; f < N; f++){
        a[e][f] = 0;
        for(int g = 0; g < N; g++) a[e][f] += b[e][g] * c[g][f];
    }
}
// a = b ^ k
void xp(T a[maxn][maxn], T b[maxn][maxn], long long k){
    if(k == 0) identity(a);
    else if(k == 1) cpy(a, b);
    else{
        xp(a, b, k / 2);
        T tmp[maxn][maxn];
        mul(tmp, a, a);
        cpy(a, tmp);
        if(k&1){
            mul(tmp, a, b);
            cpy(a, tmp);
        }
    }
}
};
const int maxn = 1111;
char g[maxn][maxn];
int main(){
	modular_space::mod = 1'000'000'007;
	int n, m; long long k; cin >> n >> m >> k;
	if(k == 0){
		cout << 1 << endl;
		return 0;
	}
	int black = 0, vadj = 0, hadj = 0;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++){
		cin >> g[i][j];
	}
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++){
		if(g[i][j] == '#'){
			black++;
			if(g[i][j+1] == '#') hadj++;
			if(g[i+1][j] == '#') vadj++;
		}
	}
	int  good_line = 0, good_col = 0;
	for(int i = 1; i <= n; i++){
		if(g[i][1] == '#' && g[i][m] == '#') good_line++;
	}
	for(int j = 1; j <= m; j++){
		if(g[1][j] == '#' && g[n][j] == '#') good_col++;
	}
	if(good_line && good_col) cout << 1 << endl;
	else if(!good_line && !good_col){
		cout << (umod(black) ^ (k - 1)) << endl;
	} else {
		umod a[2][2], b[2][2];
		if(good_line){
			a[0][0] = black;
			a[0][1] = -hadj;
			a[1][0] = 0;
			a[1][1] = good_line;
		} else {
			a[0][0] = black;
			a[0][1] = -vadj;
			a[1][0] = 0;
			a[1][1] = good_col;
		}
		M::xp(b, a, k - 1);
		cout << b[0][0] + b[0][1] << endl;
	}
	return 0;
}


Measured memory_bytes: 1280