// やったぜ！！！！！
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll mod = 1e9 + 7;

vector<string> s(1000);

using Vec = vector<ll>;
using Mat = vector<Vec>;

Mat mul(Mat a, Mat b) {
  int n = a.size();
  Mat r(n, Vec(n));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      for(int k = 0; k < n; k++) {
        (r[i][j] += a[i][k] * b[k][j] % mod) %= mod;
      }
    }
  }
  return r;
}

Mat pow(Mat a, ll k) {
  int n = a.size();
  Mat r(n, Vec(n));
  for(int i = 0; i < n; i++) r[i][i] = 1;
  while(k) {
    if(k & 1) r = mul(r, a);
    a = mul(a, a);
    k >>= 1;
  }
  return r;
}

ll modpow(ll a, ll b) {
  ll r = 1;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}

ll solve() {
  ios::sync_with_stdio(false), cin.tie(0);
  int h, w;
  ll k;
  cin >> h >> w >> k;
  if(k == 0) return 1;
  for(int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int hroll = 0, wroll = 0;
  for(int i = 0; i < h; i++)
    if(s[i][0] == s[i][w - 1] && s[i][0] == '#') { wroll = 1; break; }
  for(int j = 0; j < w; j++)
    if(s[0][j] == s[h - 1][j] && s[0][j] == '#') { hroll = 1; break; }
  if(wroll && hroll) {
    return 1;
  }
  if(hroll) {
    vector<string> rev = s;
    s = vector<string>(1000, string(1010, ' '));
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++)
      s[j][i] = rev[i][j];
    swap(h, w);
  }
  ll l = 0, r = 0, n = 0;
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(s[i][j] == '#') {
        n++;
        if(j == 0) {
          l++;
        } else {
          if(s[i][j - 1] != '#') l++;
        }
        if(s[i][(j - 1 + w) % w] != '#') r++;
      }
    }
  }
  k--;
  if(!wroll && !hroll) return modpow(n, k);
  Mat A(2, Vec(2));
  A[0][0] = l; A[0][1] = n - l;
  A[1][0] = r; A[1][1] = n - r;
  A = pow(A, k);
  return A[0][0];
}

int main() {
  cout << solve() << endl;
}

