#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int n,m,x,y,z;
LL k;
char a[1010][1010];

bool check1()
{
    repu(i,1,m)
        if (a[1][i]=='#' && a[n][i]=='#')
            return 1;
    return 0;
}

bool check2()
{
    repu(i,1,n)
        if (a[i][1]=='#' && a[i][m]=='#')
            return 1;
    return 0;
}

int power(int x,LL k)
{
    int ret=1;
    for (; k; k>>=1,x=LL(x)*x%p)
        if (k&1)
            ret=LL(ret)*x%p;
    return ret;
}

int calc(int x,int q,LL n)
{
    if (q==1)
        return n%p*x%p;
    return LL(power(q,n)-1)*x%p*power(q-1,p-2)%p;
} 

int main()
{
    scanf("%d%d%lld",&n,&m,&k);
    repu(i,1,n)
        scanf("%s",a[i]+1);
    bool flag1=check1(),flag2=check2();
    if (k<=1 || flag1 && flag2)
    {
        puts("1");
        return 0;
    }
    if (flag1)
    {
        repu(i,1,max(n,m))
            repu(j,1,i)
                swap(a[i][j],a[j][i]);
        swap(n,m);
    }
    repu(i,1,n)
        repu(j,1,m)
            if (a[i][j]=='#')
                ++x,z+=j<m && a[i][j+1]=='#';
    repu(i,1,n)
        y+=a[i][1]=='#' && a[i][m]=='#';
    int ans=power(x,k-1);
    if (y)
        ans=(ans+p-LL(z)*calc(power(y,k-2),LL(x)*power(y,p-2)%p,k-1)%p)%p;
    printf("%d\n",ans);
    return 0;
}