#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename K>
struct Matrix{
  typedef vector<K> arr;
  typedef vector<arr> mat;
  mat dat;

  Matrix(size_t r,size_t c):dat(r,arr(c,K())){}
  Matrix(mat dat):dat(dat){}

  size_t size() const{return dat.size();};
  bool empty() const{return size()==0;};
  arr& operator[](size_t k){return dat[k];};
  const arr& operator[](size_t k) const {return dat[k];};
  
  static Matrix cross(const Matrix &A,const Matrix &B){
    Matrix res(A.size(),B[0].size());    
    for(int i=0;i<(int)A.size();i++)
      for(int j=0;j<(int)B[0].size();j++)
        for(int k=0;k<(int)B.size();k++)
          res[i][j]+=A[i][k]*B[k][j];
    return res;
  }

  static Matrix identity(size_t n){
    Matrix res(n,n);
    for(int i=0;i<(int)n;i++) res[i][i]=K(1);
    return res;
  }
  
  Matrix pow(long long n) const{
    Matrix a(dat),res=identity(size());
    while(n){
      if(n&1) res=cross(res,a);
      a=cross(a,a);      
      n>>=1;
    }
    return res;
  }
};


template<typename T,T MOD = 1000000007>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
  
  Mint inv(){return pow(MOD-2);}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
  
  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-(){return v?MOD-v:v;}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
  
};
//INSERT ABOVE HERE

signed main(){
  Int h,w,k;
  cin>>h>>w>>k;
  vector<string> s(h);
  for(int i=0;i<h;i++) cin>>s[i];

  int flg1=0,flg2=0;
  for(int i=0;i<h;i++)
    flg1|=s[i][0]=='#'&&s[i][w-1]=='#';
  for(int j=0;j<w;j++)
    flg2|=s[0][j]=='#'&&s[h-1][j]=='#';

  if(flg1&&flg2){
    cout<<1<<endl;
    return 0;
  }
  
  if(flg2){
    vector<string> s2(w,string(h,' '));    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
        s2[j][i]=s[i][j];
    swap(s,s2);
    swap(h,w);
  }

  using M = Mint<int>;
  using MM = Matrix<M>;

  Int a=0,b=0,c=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      a+=s[i][j]=='#';
      if(j+1<w)
        b+=s[i][j]=='#'&&s[i][j+1]=='#';
    }
    c+=s[i][0]=='#'&&s[i][w-1]=='#';
  }
  
  if(!flg1&&!flg2){
    cout<<M(a).pow(k-1).v<<endl;
    return 0;
  }

  
  MM A(2,2);
  A[0][0]=M(a);A[0][1]=M(-b);
  A[1][0]=M(0);A[1][1]=M( c);

  MM B(2,1);
  B[0][0]=M(1);
  B[1][0]=M(1);

  cout<<MM::cross(A.pow(k-1),B)[0][0].v<<endl;
  return 0;
}


Measured memory_bytes: 2304