#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


struct Matrix{
    int h, w;
    vector<i64> v;

    Matrix(int h, int w) : h(h), w(w), v(h * w, 0){}

    Matrix(vector<vector<i64>> v_) : h(v_.size()), w(v_[0].size()), v(h * w){
        for(int i = 0; i < h; ++i)
            for(int j = 0; j < w; ++j)
                v[i * w + j] = v_[i][j];
    }

    static Matrix makeUnit(int n){
        Matrix mat(n, n);
        for(int i = 0; i < n; ++i)
            mat.at(i, i) = 1;
        return mat;
    }

    static Matrix modMul(const Matrix& a, const Matrix& b, const int mod = MOD){
        assert(a.w == b.h);
        Matrix ret(a.h, b.w);
        for(int i = 0; i < a.h; ++i)
            for(int k = 0; k < a.w; ++k)
                for(int j = 0; j < b.w; ++j)
                    ret.v[i * b.w + j] = (ret.v[i * b.w + j] + a.v[i * a.w + k] * b.v[k * b.w + j]) % mod;
        return ret;
    }

    i64& at(int i, int j){
        assert(0 <= i && i <= h && 0 <= j && j < w);
        return v[i * h + j];
    };

    Matrix pow(i64 x, const i64 mod = MOD){
        assert(h == w);
        auto mat = x & 1L ? *this : makeUnit(h);
        auto u = *this;
        while(u = modMul(u, u, mod), x >>= 1L)
            if(x & 1L)
                mat = modMul(mat, u, mod);
        return mat;
    }

    Matrix& operator+=(const Matrix& mat){
        assert(h == mat.h && w == mat.w);
        for(int i = 0; i < h * w; ++i)
            v[i] += mat.v[i];
        return *this;
    }

    Matrix& operator-=(const Matrix& mat){
        assert(h == mat.h && w == mat.w);
        for(int i = 0; i < h * w; ++i)
            v[i] -= mat.v[i];
        return *this;
    }

    Matrix& operator%=(const i64 mod){
        for(int i = 0; i < h * w; ++i)
            v[i] %= mod;
        return *this;
    }

    Matrix operator*(const Matrix& mat){
        assert(w == mat.h);
        Matrix ret(h, mat.w);
        for(int i = 0; i < h; ++i)
            for(int k = 0; k < w; ++k)
                for(int j = 0; j < mat.w; ++j)
                    ret.v[i * mat.w + j] += v[i * w + k] * mat.v[k * mat.w + j];
        return ret;
    }

    Matrix operator+(const Matrix& mat){return Matrix(*this) += mat;}
    Matrix operator-(const Matrix& mat){return Matrix(*this) -= mat;}
    Matrix operator%(const i64 mod){return Matrix(*this) %= mod;}
    Matrix& operator*=(const Matrix& mat){return *this = *this * mat;}
};



signed main(){
    int h, w;
    i64 k;
    cin >> h >> w >> k;
    vector<bitset<1000>> bs(h);
    vector<vector<int>> flag(h, vector<int>(w, -1));

    for(int i = 0; i < h; ++i){
        string s;
        cin >> s;
        for(int j = 0; j < w; ++j)
            bs[i].set(j, s[j] == '#');
    }

    bool f1 = false, f2 = false;
    for(int i = 0; i < h; ++i)
        f1 |= (bs[i][0] && bs[i][w - 1]);
    for(int j = 0; j < w; ++j)
        f2 |= (bs[0][j] && bs[h - 1][j]);

    if(f1 && f2){
        cout << 1 << endl;
        return 0;
    }

    i64 a = 0, b = 0, c = 0;
    if(f1){
        for(int i = 0; i < h; ++i){
            c += (bs[i][0] && bs[i][w - 1]);
            for(int j = 0; j < w; ++j){
                a += bs[i][j];
                if(j != w - 1)
                    b += (bs[i][j] && bs[i][j + 1]);
            }
        }
    }else{
        for(int j = 0; j < w; ++j){
            c += (bs[0][j] && bs[h - 1][j]);
            for(int i = 0; i < h; ++i){
                a += bs[i][j];
                if(i != h - 1)
                    b += (bs[i][j] && bs[i + 1][j]);
            }
        }
    }

    function<i64(i64,i64)> mpow = [&](i64 x, i64 y){
        i64 val = y & 1 ? x : 1;
        i64 base = x;
        while(base = (base * base) % MOD, y >>= 1){
            if(y & 1)
                val = (val * base) % MOD;
        }
        return val;

    };

    if(!f1 && !f2){
        cout << mpow(a, k - 1) << endl;
        return 0;
    }


    vector<vector<i64>> v = {{a, (MOD - b) % MOD}, {0, c}};
    Matrix mat(v);
    auto ret = mat.pow(k - 1);

    auto mul = Matrix::modMul(ret, Matrix(vector<vector<i64>>(2, vector<i64>(1, 1))));
    cout << mul.at(0, 0) << endl;

}


Measured memory_bytes: 4352