#include <cstdio>
#include <cstdlib>

using namespace std;

#define ll long long

#define DEFMOD(mod, type) typedef ModInt<mod, int> type;     \
                          type operator "" _m(unsigned long long x) {   \
                              type res = x; return res; \
                          }

template<int mod, class itype> struct ModInt {
    int val;
    ModInt() {
        val = 0;
    }
    ModInt(int a) {
        val = a % mod;
    }
};

/* MODIFY AS NEEDED */

DEFMOD(1000000007, mi)

template<int mod, class itype> ModInt<mod, itype> fpow(ModInt<mod, itype> base, ll exponent)
{
    ModInt<mod, itype> ans = 1_m;
    ModInt<mod, itype> cur = base;
    while (exponent) {
        if (exponent & 1) ans = ans * cur;
        cur = cur * cur; exponent >>= 1;
    }
    return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator+(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ll val = (ll)(a.val) + (ll)(b.val);
    if (val >= mod) val -= mod;
    ans.val = val; return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator-(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ans.val = a.val - b.val;
    if (ans.val < 0) ans.val += mod;
    return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator*(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ans.val = ((ll)(a.val) * (ll)(b.val)) % (ll)mod;
    return ans;
}

// PRIME MOD ONLY!
template<int mod, class itype> ModInt<mod, itype> operator/(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
#ifndef ONLINE_JUDGE
    if (b.val == 0) {
        fprintf(stderr, "Division by zero :(\n"); abort();
    }
#endif
    return a * fpow(b, mod - 2);
}

template<int r, int c, class T> struct Matrix {
    T a[r+1][c+1];
    Matrix() {
        for (int i = 1; i <= r; i++) {
            for (int j = 1; j <= c; j++) {
                a[i][j] = 0;
            }
        }
    }
};

template<int r, int c, int k, class T>
void matrix_mult(Matrix<r, k, T>& ans, const Matrix<r, c, T>& first,
    const Matrix<c, k, T>& second) {
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= k; j++) {
            ans.a[i][j] = 0;
        }
    }
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= k; j++) {
            for (int x = 1; x <= c; x++) {
                ans.a[i][j] = ans.a[i][j] + first.a[i][x] * second.a[x][j];
            }
        }
    }
}

template<int n, class T>
void matrix_power(Matrix<n, n, T>& base, ll exponent)
{
    Matrix<n, n, T> cur = base;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            base.a[i][j] = (i == j ? 1 : 0);
        }
    }
    while (exponent) {
        Matrix<n, n, T> tmp;
        if (exponent & 1LL) {
            matrix_mult(tmp, base, cur);
            base = tmp;
        }
        matrix_mult(tmp, cur, cur);
        cur = tmp; exponent >>= 1LL;
    }
}

int n, m; ll k;

bool grid[1005][1005];
char s[1005];

int main()
{
    scanf("%d%d%lld", &n, &m, &k);
    if (k == 0) {
        printf("1"); return 0;
    }
    int blackcnt = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%s", s + 1);
        for (int j = 1; j <= m; j++) {
            grid[i][j] = (s[j] == '#');
            if (s[j] == '#') blackcnt++;
        }
    }
    int hor_cnt = 0, ver_cnt = 0;
    int hor_adj = 0, ver_adj = 0;
    for (int i = 1; i <= n; i++) {
        if (grid[i][1] && grid[i][m]) hor_cnt++;
    }
    for (int i = 1; i <= m; i++) {
        if (grid[1][i] && grid[n][i]) ver_cnt++;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < m; j++) {
            if (grid[i][j] && grid[i][j+1]) hor_adj++;
        }
    }
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= m; j++) {
            if (grid[i][j] && grid[i+1][j]) ver_adj++;
        }
    }
    if (hor_cnt && ver_cnt) {
        printf("1"); return 0;
    }
    if (!(hor_cnt || ver_cnt)) {
        mi ans = fpow((mi)blackcnt, k - 1);
        printf("%d", ans.val);
        return 0;
    }

    if (ver_cnt) {
        hor_cnt = ver_cnt;
        hor_adj = ver_adj;
    }
    Matrix<2, 2, mi> trans;
    trans.a[1][1] = hor_cnt;
    trans.a[1][2] = hor_adj;
    trans.a[2][1] = 0;
    trans.a[2][2] = blackcnt;
    matrix_power(trans, k - 1);
    mi ans = fpow((mi)blackcnt, k - 1) - trans.a[1][2];
    printf("%d", ans.val);
    return 0;
}


Measured memory_bytes: 4168