#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

ll mod_pow(ll a,ll x){
  ll ret=1;
  while(x>0){
    if(x&1){(ret*=a)%=MOD;}
    x>>=1;
    (a*=a)%=MOD;
  }
  return ret;
}

template<long long int mod=1000000007>
struct Mod_Int{
    typedef long long int ll;
    typedef pair<ll,ll> pll;
    typedef Mod_Int<mod> M;
    ll a;
    
    ll mod_pow(ll a,ll x){
        a%=mod;
        ll ans=1;
        for(int i=0;i<63;i++){
            if(x>>i&1){ans*=a; ans%=mod;}
            a*=a;
            a%=mod;
        }
        return ans;
    }
    
    pll Ex_gcd(ll a,ll b){
        if(b==0){return {1,0};}
        pll ret=Ex_gcd(b,a%b);
        ret.F-=a/b*ret.S;
        return {ret.S,ret.F};
    }
    
    ll prime_R(ll a){
        return mod_pow(a,mod-2);
    }
    
    ll R(ll a){
        ll ret=Ex_gcd(a,mod).F;
        ret%=mod;
        if(ret<0){ret+=mod;}
        return ret;
    }
    
    Mod_Int(ll A=1):a(A){
        a%=mod;
        if(a<0){a+=mod;}
    }
    
    Mod_Int(const M &b):a(b.a){}
    
    M & operator += (const M &b){
        a+=b.a;
        if(a>=mod){a-=mod;}
        return *this;
    }
    
    M operator + (const M &b) const {
        M c=*this;
        return c+=b;
    }
    
    M & operator -= (const M &b){
        a-=b.a;
        if(a<0){a+=mod;}
        return *this;
    }
    
    M operator - (const M &b) const {
        M c=*this;
        return c-=b;
    }
    
    M & operator *= (const M &b){
        (a*=b.a)%=mod;
        return *this;
    }
    
    M operator * (const M &b) const {
        M c=*this;
        return c*=b;
    }
    
    M & operator /= (const M &b){
        (a*=R(b.a))%=mod;
        return *this;
    }
    
    M operator / (const M &b) const {
        M c=*this;
        return c/=b;
    }
    
    M & mod_pow_equal(ll x){
        ll ans=1;
        while(x>0){
            if(x&1){ans*=a; ans%=mod;}
            a*=a;
            a%=mod;
            x>>=1;
        }
        a=ans;
        return *this;
    }
    
    M mod_pow(ll x){
        M c(a);
        return c.mod_pow_equal(x);
    }
    
    bool operator == (const M &b) const {return a==b.a;}
    
    bool operator != (const M &b) const {return a!=b.a;}
    
    bool operator <= (const M &b) const {return a<=b.a;}
    
    bool operator < (const M &b) const {return a<b.a;}
    
    bool operator > (const M &b) const {return a>b.a;}
    
    bool operator >= (const M &b) const {return a>=b.a;}
    
    M & operator = (const M &b){
        a=b.a;
        return *this;
    }
    
    M & operator = (const ll &b){
        (a=b)%=mod;
        if(a<0){a+=mod;}
        return *this;
    }
};

template<long long MOD>istream & operator >> (istream &i,Mod_Int<MOD> &A){ll a; cin>>a; A=Mod_Int<MOD>(a); return i;}
template<long long MOD>ostream & operator << (ostream &i,const Mod_Int<MOD> &A){i<<A.a; return i;}

using Int=Mod_Int<MOD>;

//sum_{i=0}^{x} a_0 k^i
Int sum(Int a_0,Int k,ll x){
  if(k==1){return a_0*(x+1);}
  return (k.mod_pow(x+1)-1)/(k-1)*a_0;
}

//sum_{i=0}^{n} a^i b^{n-i}
Int cul(Int a,Int b,ll n){
  return sum(b.mod_pow(n),a/b,n);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll H,W,K;
  cin>>H>>W>>K;
  if(K<=1){cout<<1<<endl; return 0;}
  K--;
  vector<string> A(H);
  cin>>A;
  bool row=false,col=false;
  for(int i=0;i<W;i++){
    if(A[0][i]=='#' && A[H-1][i]=='#'){row=true;}
  }
  for(int i=0;i<H;i++){
    if(A[i][0]=='#' && A[i][W-1]=='#'){col=true;}
  }
  if(row && col){
    cout<<1<<endl;
    return 0;
  }
  else if(!row && !col){
    ll cnt=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(A[i][j]=='#'){
          cnt++;
        }
      }
    }
    cout<<mod_pow(cnt,K)<<endl;
    return 0;
  }
  if(row){
    vector<string> B(W);
    for(int j=0;j<W;j++){
      for(int i=0;i<H;i++){
        B[j].push_back(A[i][j]);
      }
    }
    swap(H,W);
    A=B;
  }
  K--;
  Int B=0,R=0,uku=0,nx=0,C=0;
  for(int i=0;i<H;i++){
    bool all=true;
    for(int j=0;j<W;j++){
      A[i][j]=(A[i][j]=='#'?1:0);
      all=all&A[i][j];
      if(A[i][j] && (j==0 || A[i][j-1]==0)){C+=1;}
      if(A[i][j] && j>0 && A[i][j-1]){nx+=1;}
      if(A[i][j]){uku+=1;}
    }
    if(A[i][0] && A[i].back()){B+=1; R+=1;}
  }
  if(W==1){cout<<B.mod_pow(K+1)<<endl; return 0;}
  Int ans=C*uku.mod_pow(K);
  ans-=nx*B*cul(R,uku,K-1);
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 7144