#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int MOD = (int) 1e9 + 7;
const int K = 3;

int Pow(int x, int64_t y) {
    int ret = 1;
    for (; y > 0; y /= 2) {
        if (y & 1) {
            ret = (int64_t) ret * x % MOD;
        }
        x = (int64_t) x * x % MOD;
    }
    return ret;
}

struct Matrix {
    int a[K][K];
    Matrix():
        a{0} {}
    Matrix operator*(const Matrix& other) const {
        Matrix res;
        for (int i = 0; i < K; ++i) {
            for (int j = 0; j < K; ++j) {
                for (int k = 0; k < K; ++k) {
                    res.a[i][j] = (res.a[i][j] + (int64_t) a[i][k] * other.a[k][j]) % MOD;
                }
            }
        }
        return res;
    }

    static Matrix identity() {
        Matrix res;
        for (int i = 0; i < K; ++i) {
            res.a[i][i] = 1;
        }
        return res;
    }
};

Matrix Pow(Matrix x, int64_t y) {
    Matrix ret = Matrix::identity();
    for (; y > 0; y /= 2) {
        if (y & 1) {
            ret = ret * x;
        }
        x = x * x;
    }
    return ret;
}

vector<string> rotate(const vector<string>& a) {
    int n = SZ(a);
    int m = SZ(a[0]);
    vector<string> b(m, string(n, '.'));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            b[j][n - i - 1] = a[i][j];
        }
    }
    return b;
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int h, w;
    cin >> h >> w;

    int64_t k;
    cin >> k;

    vector<string> mat(h);
    for (int i = 0; i < h; ++i) {
        cin >> mat[i];
    }

    bool connectedVerticaly = false, connectedHorizontaly = false;
    for (int i = 0; i < h; ++i) {
        if (mat[i][0] == '#' && mat[i][w - 1] == '#') {
            connectedHorizontaly = true;
        }
    }
    for (int j = 0; j < w; ++j) {
        if (mat[0][j] == '#' && mat[h - 1][j] == '#') {
            connectedVerticaly = true;
        }
    }
    if (k == 0) {
        cout << "1\n";
    }
    if (connectedVerticaly && connectedHorizontaly) {
        cout << "1\n";
    } else if (!connectedVerticaly && !connectedHorizontaly) {
        int cnt = 0;
        for (const string& p: mat) {
            cnt += count(p.begin(), p.end(), '#');
        }
        cout << Pow(cnt, k - 1) << '\n';
    } else {
        if (connectedHorizontaly) {
            mat = rotate(mat);
            swap(h, w);
        }
        int x = 0, y = 0, z = 0;
        for (const string& p: mat) {
            y += count(p.begin(), p.end(), '#');
        }
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                int add = mat[i][j] == '#' && (i == 0 || mat[i - 1][j] != '#');
                x += add;
                y -= add;
            }
        }
        for (int j = 0; j < w; ++j) {
            int add = mat[0][j] == '#' && mat[h - 1][j] == '#';
            z += add;
            x -= add;
        }
        Matrix ans;
        ans.a[0][0] = x + z;
        ans.a[0][1] = x;
        ans.a[0][2] = x;
        ans.a[1][0] = y;
        ans.a[1][1] = y + z;
        ans.a[1][2] = y;
        ans.a[2][0] = 0;
        ans.a[2][1] = 0;
        ans.a[2][2] = z;

        ans = Pow(ans, k - 1);
        int fans = (ans.a[0][2] + ans.a[2][2]) % MOD;
        cout << fans << '\n';
    }
}

Measured memory_bytes: 2304