/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline int ri() {int x; scanf("%d", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


char b[1005][1005], t[1005][1005];
LL n, m, level;

//mod int
struct mint{
  const static long long mod = 1e9 + 7;
  long long x;
  mint():x(0){}       
  mint(long long x):x(((x%mod)+mod)%mod){};
  mint operator+=(const mint&a){if((x+=a.x)>=mod) x-=mod; return *this;}
  mint operator-=(const mint&a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint operator*=(const mint&a){(x*=a.x)%=mod; return *this;}
  mint operator*(const mint&a){return mint(*this)*=a;}
  mint operator-(const mint&a){return mint(*this)-=a;}
  mint operator+(const mint&a){return mint(*this)+=a;}
  template<typename T>mint operator*(const T&a){return mint(*this)*=a;}
  template<typename T>mint operator-(const T&a){return mint(*this)-=a;}
  template<typename T>mint operator+(const T&a){return mint(*this)+=a;}
  template<typename T>friend mint operator*(T x,const mint&m){return mint(x)*=m;}
  template<typename T>friend mint operator-(T x,const mint&m){return mint(x)-=m;}
  template<typename T>friend mint operator+(T x,const mint&m){return mint(x)+=m;}
  bool operator==(const mint& a)const{ return x == a.x;}
  operator long long () const {return x;}
};
mint pw(mint a, long long b){mint res(1);while(b){if(b&1)res*=a;a*=a;b>>=1;}return res;}
mint inv(mint a){return pw(a, mint::mod - 2);}
//mod int

const int maxn = 2005;

//matrix
template<typename T> 
struct matrix {
    const static int size = 2;
    T m[size][size];
    matrix() {memset(m, 0, sizeof(m));}
};
template<typename T> 
matrix<T> mul(matrix<T> a, matrix<T> b) {
  matrix<T> c;
  for (int i = 0; i < a.size; i ++) 
    for (int j = 0; j < a.size; j ++) 
      for (int k = 0; k < a.size; k ++)
        c.m[i][k] += (a.m[i][j] * b.m[j][k]);
    return c;
}
template<typename T> 
matrix<T> pw(matrix<T> a, long long b) {
    matrix<T> res;
    for (int i = 0; i < a.size; i ++) res.m[i][i] = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
    }
    return res;
}
//matrix

int main() {
  #ifdef _TEST_
  freopen("input.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
  #endif
  scanf("%lld%lld%lld", &n, &m, &level);
  rep(i, n) scanf("%s", b[i]);
  int hc = 0, vc = 0, s = 0;
  rep(i, n) if (b[i][0] == '#' && b[i][m - 1] == '#') hc = 1;
  rep(i, m) if (b[0][i] == '#' && b[n - 1][i] == '#') vc = 1;
  rep(i, n) rep(j, m) s += b[i][j] == '#';
  if (hc == 0 && vc == 0) {
    cout << pw(s, level - 1) << endl;
    return 0;
  }
  if ((hc == 1 && vc == 1) || level == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (vc == 1) {
    rep(i, n) rep(j, m) t[j][i] = b[i][j];
    rep(i, n) rep(j, m) b[j][i] = t[j][i];
    swap(n, m);
  }
  int d = 0, k = 0;
  rep(i, n) rep(j, m - 1) if (b[i][j] == '#' && b[i][j + 1] == '#') d ++;
  rep(i, n) if (b[i][0] == '#' && b[i][m - 1] == '#') k ++;
  matrix<mint> M;
  M.m[0][0] = s;
  M.m[0][1] = -d;
  M.m[1][1] = k;
  
  //cout << s << ' ' << d << ' ' << k << endl;
  M = pw(M, level - 1);

  cout << M.m[0][0] + M.m[0][1] << endl;

  return 0;
}


Measured memory_bytes: 2176