// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define mod 1000000007



int n,m,cnt,flag1,flag2,s1,s2;

long long k;

char s[2001][2001];



long long quickpow(long long base,long long to)

{

    if(to<=0)return 1;

    if(to==1)return base;

    long long mid=quickpow(base,to>>1);

    if(to&1)return mid*mid%mod*base%mod;

    else return mid*mid%mod;

}



struct Matrix{

    long long a[3][3];

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

    Matrix operator*(Matrix &m)

    {

        Matrix ans;

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

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

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

                    ans.a[i][j]=(ans.a[i][j]+a[i][k]*m.a[k][j]%mod)%mod;

        return ans;

    }

};



int main()

{

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

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

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

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

    {

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

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

            {

                ++cnt;

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

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

            }

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

    }

    for(int i=1;i<=m;++i)if(s[1][i]=='#' && s[n][i]=='#')++flag2;

    if(flag1 && flag2)

    {

        puts("1");

        return 0;

    }

    if(!flag1 && !flag2)

    {

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

        return 0;

    }

    if(!flag1)swap(flag1,flag2),swap(s1,s2);

    Matrix A;

    A.a[1][1]=cnt;

    A.a[2][1]=s1;

    A.a[2][2]=flag1;

    --k;

    Matrix ANS;

    ANS.a[1][1]=ANS.a[2][2]=1;

    while(k)

    {

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

        A=A*A;

        k>>=1;

    }

    printf("%lld\n",(ANS.a[1][1]-ANS.a[2][1]+mod)%mod);

}

// Faster C++ solution for the same problem (measured speedup: 5.051529779494636x):
#include <cstdio>

#include <algorithm>

#include <cstring>

#include <cctype>

using namespace std;

typedef long long int64;

inline int read(int f = 1, int x = 0, char ch = ' ')

{

    while(!isdigit(ch  = getchar())) if(ch == '-') f = -1;

    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();

    return f*x;

}

const int N = 1e3+5, P = 1e9+7;

struct Matrix

{

    int __[2][2];

    Matrix() { memset(__, 0, sizeof(__)); }

    int* operator [] (const int i) { return __[i]; }

    Matrix operator * (Matrix &_) const

    {

        Matrix ret;

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

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

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

                    ret[i][j] = (ret[i][j]+1ll*__[i][k]*_[k][j]%P)%P;

        return ret;

    }  

    void set() { for(int i = 0; i < 2; ++i) __[i][i] = 1; }

}f;

Matrix qpow(Matrix a, int64 b)

{

    Matrix ret; ret.set();

    for( ; b; b >>= 1, a = a*a) if(b&1) ret = ret*a;

    return ret;

}

int n, m;

int64 k;

char s[N][N];

int p, q, a, b, c;

int main()

{

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

    for(int i = 1; i <= n; ++i) scanf("%s", s[i]+1);

    for(int i = 1; i <= n; ++i) p += s[i][1]=='#'&&s[i][m]=='#';

    for(int i = 1; i <= m; ++i) q += s[1][i]=='#'&&s[n][i]=='#';

    if((p&&q)||k < 2) return puts("1"), 0; b = p|q;

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

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

        {

            c += s[i][j] == '#';

            a += s[i][j] == '#'&&s[i][j+1] == '#'&&p;

            a += s[i][j] == '#'&&s[i+1][j] == '#'&&q;

        }

    f[0][0] = c, f[1][0] = a, f[1][1] = b; f = qpow(f, k-1);

    printf("%d\n", (f[0][0]-f[1][0]+P)%P);

    return 0;

}

/* 

3 3 2

.#.

###

#.#

*/