// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <algorithm>



using namespace std;

#define MOD 1000000007

#define ll long long

#define rint register int

#define gc() getchar()

inline ll read(ll ans = 0, rint sgn = ' ', rint ch = gc())

{

	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());

	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());

	return sgn-'-'?ans:-ans;

}

int H, W, a, b, c, row, col; char s[1005][1005]; ll K;

inline int fastpow(int s, ll n){int a = 1; for(; n; n&1 ? a = 1ll*a*s%MOD : 0, s = 1ll*s*s%MOD, n >>= 1); return a;}

struct Matrix{int c[2][2]; Matrix(){} Matrix(int c00, int c01, int c10, int c11){c[0][0]=c00,c[0][1]=c01,c[1][0]=c10,c[1][1]=c11;}}U,S,A,I(1,0,0,1),F;

inline Matrix operator * (Matrix &A, Matrix &B)

{

	return Matrix((1ll*A.c[0][0]*B.c[0][0]+1ll*A.c[0][1]*B.c[1][0])%MOD,

				  (1ll*A.c[0][0]*B.c[0][1]+1ll*A.c[0][1]*B.c[1][1])%MOD,

				  (1ll*A.c[1][0]*B.c[0][0]+1ll*A.c[1][1]*B.c[1][0])%MOD,

				  (1ll*A.c[1][0]*B.c[0][1]+1ll*A.c[1][1]*B.c[1][1])%MOD);

}

inline Matrix operator ^ (Matrix S, ll n){for(A = I; n; S = S*S, n >>= 1) if(n&1) A = A*S; return A;}

int main()

{

	H = read(), W = read(), K = read(); if(!K){puts("1"); return 0;}

	for(rint i = 1; i <= H; scanf("%s",s[i]+1), c += s[i][1]=='#'&&s[i][W]=='#', i++); row = c;

	for(rint j = 1; j <= W; c += s[1][j]=='#'&&s[H][j]=='#', j++); col = c-row;

	for(rint i = 1, j; i <= H; i++)

		for(j = 1; j <= W; s[i][j]=='#' ? ++a, b += row?j<W&&s[i][j+1]=='#':i<H&&s[i+1][j]=='#' : 0, j++);

	if(row&&col){puts("1"); return 0;} if(!row&&!col){printf("%d\n",fastpow(a,~-K)); return 0;}

	U = Matrix(a,MOD-b,0,c), F = Matrix(1,0,1,0), S = U^~-K, F = S*F, printf("%d\n",F.c[0][0]); return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

#define MAXN 1010

#define MO 1000000007

#define LL long long

int cnt,s1,s2,f1,f2,n,m;

LL k;

char s[MAXN][MAXN];

LL PowMod(LL a,LL b)

{

	b%=(MO-1);

	LL ret=1;

	while(b)

	{

		if(b&1) ret=ret*a%MO;

		a=a*a%MO;

		b>>=1;

	}

	return ret;

}

struct maz

{

	LL a[2][2];

	maz(){memset(a,0,sizeof a);};

	maz operator*(maz &m)

	{

		maz ret;

		for(int i=0;i<2;i++)

			for(int j=0;j<2;j++)

				for(int k=0;k<2;k++)

					ret.a[i][j]=(ret.a[i][j]+a[i][k]*m.a[k][j]%MO)%MO;

		return ret;

	}

};

int main()

{

	scanf("%d%d%lld",&n,&m,&k);

	for(int i=1;i<=n;i++)

	{

		scanf("%s",s[i]+1);

		for(int j=1;j<=m;j++)

			if(s[i][j]=='#')

			{

				cnt++;

				s1+=(s[i-1][j]=='#');

				s2+=(s[i][j-1]=='#');

			}

		if(s[i][1]=='#'&&s[i][m]=='#') f2++;

		if(i==n)

		{

			for(int j=1;j<=m;j++)

				if(s[1][j]=='#'&&s[n][j]=='#') f1++;

		}

	}

	if((f1&&f2)||k==0)

	{

		printf("1\n");

		return 0;

	}

	else if(f1==0&&f2==0)

	{

		printf("%lld\n",PowMod(cnt,k-1));

		return 0;

	}

	if(f1==0)

	{

		swap(f1,f2);

		swap(s1,s2);

	}

	maz A,ans;

	A.a[0][0]=cnt,A.a[1][0]=s1,A.a[1][1]=f1;

	ans.a[0][0]=ans.a[1][1]=1;

	k--;

	while(k)

	{

		if(k&1) ans=ans*A;

		A=A*A;

		k>>=1;

	}

	printf("%lld\n",(ans.a[0][0]-ans.a[1][0]+MO)%MO);

}

// Fastest known solution for this problem: