#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }


const LL MOD = 1e9+7;
const int SIZE = 2;
struct Arr {
    unsigned D[SIZE];
    Arr() { memset(D, 0, sizeof D); }
    unsigned &operator[](int i) { return D[i]; }
    const unsigned &operator[](int i) const { return D[i]; }
    Arr& operator+=(const Arr &y) {
	for (int i=0; i<SIZE; i++)
	    if ((D[i] += y[i]) >= MOD) D[i] -= MOD;
	return *this;
    }
    Arr& operator-=(const Arr &y) {
	for (int i=0; i<SIZE; i++)
	    if ((D[i] += MOD-y[i]) >= MOD) D[i] -= MOD;
	return *this;
    }
    Arr operator+(const Arr &y) const { return Arr(*this) += y; }
    Arr operator-(const Arr &y) const { return Arr(*this) -= y; }
};

struct Mat {
    unsigned D[SIZE][SIZE];
    Mat() { memset(D, 0, sizeof D); }
    unsigned (&operator[](int i))[SIZE] { return D[i]; }
    const unsigned (&operator[](int i) const)[SIZE] { return D[i]; }
    static unsigned long long z[SIZE];
    Mat& operator+=(const Mat &y) {
	for (int i=0; i<SIZE; i++)
	    for (int j=0; j<SIZE; j++)
		if ((D[i][j] += y[i][j]) >= MOD) D[i][j] -= MOD;
	return *this;
    }
    Mat& operator-=(const Mat &y) {
    	for (int i=0; i<SIZE; i++)
	    for (int j=0; j<SIZE; j++)
		if ((D[i][j] += MOD-y[i][j]) >= MOD) D[i][j] -= MOD;
	return *this;
    }
    Mat& operator*=(const Mat &y) { return *this = *this * y; }
    Mat operator+(const Mat &y) const { return Mat(*this) += y; }
    Mat operator-(const Mat &y) const { return Mat(*this) -= y; }
    Mat operator*(const Mat &y) const {
	Mat r = Mat();
	memset(z, 0, sizeof z);
	for (int i=0; i<SIZE; i++) {
	    for (int k=0; k<SIZE; k++) {
		for (int j=0; j<SIZE; j++)
		    z[j] += (unsigned long long)D[i][k] * y[k][j];
		if ((k&7)==7)
		    for (int j=0; j<SIZE; j++)
			z[j] %= MOD;
	    }
	    for (int j=0; j<SIZE; j++) {
		r[i][j] = z[j] % MOD;
		z[j] = 0;
	    }
	}
	return r;
    }
    Arr operator*(const Arr &y) const {
	Arr r = Arr();
	memset(z, 0, sizeof z);
	for (int i=0; i<SIZE; i++) {
	    for (int j=0; j<SIZE; j++) {
		z[i] += (unsigned long long)D[i][j] * y[j];
		if (z[i] & (1LL<<63)) z[i] %= MOD;
	    }
	    r[i] = z[i] % MOD;
	    z[i] = 0;
	}
	return r;
    }
    Mat pow(unsigned long long y) const {
	Mat x(*this), r = I();
	for (; y; y>>=1) {
	    if (y&1) r *= x;
	    x *= x;
	}
	return r;
    }
    Arr powmul(unsigned long long y, Arr z) const {
	Mat x(*this);
	for (; y; y>>=1) {
	    if (y&1) z = x * z;
	    x *= x;
	}
	return z;
    }
    static Mat I() {
	Mat x = Mat();
	for (int i=0; i<SIZE; i++) x[i][i] = 1;
	return x;
    }
};
unsigned long long Mat::z[SIZE];

LL powMod(LL x, LL y, LL m) {
    LL r = 1;
    for (; y; y>>=1) {
	if (y & 1) r = r * x % m;
	x = x * x % m;
    }
    return r;
}

int H, W;
LL K;
char F[1111][1111];
int main() {
    scanf("%d%d%lld", &H, &W, &K);
    REP (i, H) scanf("%s", F[i]);

    int ver = 0, hor = 0;
    REP (i, H) if (F[i][0] == '#' && F[i][W-1] == '#') hor++;
    REP (j, W) if (F[0][j] == '#' && F[H-1][j] == '#') ver++;
    int a = 0;
    REP (i, H) REP (j, W) {
	if (F[i][j] == '#') a++;
    }

    int ans = 0;
    if ((hor && ver) || K == 0) ans = 1;
    else if (!hor && !ver) ans = powMod(a, K-1, MOD);
    else {
	int b = 0;
	REP (i, H) REP (j, W) {
	    if (hor && F[i][j] == '#' && F[i][j+1] == '#') b++;
	    if (ver && F[i][j] == '#' && F[i+1][j] == '#') b++;
	}
	Mat m = Mat();
	m[0][0] = a; m[0][1] = (MOD-b) % MOD; m[1][1] = hor + ver;
	Arr x = Arr();
	x[0] = 1; x[1] = 1;
	Arr y = m.powmul(K-1, x);
	ans = y[0];
    }

    printf("%d\n", ans);


    return 0;
}



Measured memory_bytes: 1280