#include <iostream>
#include <string>

#define MOD (1000 * 1000 * 1000 + 7)

#define MAXN 1000

std::string s;
char m[MAXN][MAXN];
char aux[MAXN][MAXN];

int a[2][2], r[2][2];
long long b[2][2];

inline void rot(int &nrlin, int &nrcol) {
    for (int i = 0; i < nrlin; i++)
        for (int j = 0; j < nrcol; j++)
            aux[j][i] = m[i][j];
    int r = nrlin;
    nrlin = nrcol;
    nrcol = r;
    for (int i = 0; i < nrlin; i++)
        for (int j = 0; j < nrcol; j++)
            m[i][j] = aux[i][j];
}

inline int sum(int nrlin, int nrcol) {
    int ans = 0;
    for (int i = 0; i < nrlin; i++)
        for (int j = 0; j < nrcol; j++)
            ans += (m[i][j] == '#');
    return ans;
}

inline int per(int nrlin, int nrcol) {
    int ans = 0;
    for (int i = 0; i < nrlin; i++)
        for (int j = 1; j < nrcol; j++)
            ans += (m[i][j] == '#' && m[i][j - 1] == '#');
    return ans;
}

inline int era(int nrlin, int nrcol) {
    int ans = 0;
    for (int i = 0; i < nrlin; i++)
        ans += (m[i][0] == '#' && m[i][nrcol - 1] == '#');
    return ans;
}

inline int lgput(int a, long long n) {
    int r = 1;
    while (n) {
        if (n % 2) r = 1LL * r * a % MOD;
        n /= 2;
        a = 1LL * a * a % MOD;
    }
    return r;
}

inline void inmult(long long n) {
    r[0][0] = r[1][1] = 1;
    while (n) {
        if (n % 2) {
            for (int i = 0; i < 2; i++)
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 2; k++)
                        b[i][j] += 1LL * r[i][k] * a[k][j];
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    r[i][j] = b[i][j] % MOD;
                    b[i][j] = 0;
                }
            }
        }
        for (int i = 0; i < 2; i++)
            for (int j = 0; j < 2; j++)
                for (int k = 0; k < 2; k++)
                    b[i][j] += 1LL * a[i][k] * a[k][j];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                a[i][j] = b[i][j] % MOD;
                b[i][j] = 0;
            }
        }
        n /= 2;
    }
}

int main() {
    int nrlin, nrcol;
    long long k;

    std::cin >> nrlin >> nrcol >> k;

    for (int i = 0; i < nrlin; i++) {
        std::cin >> s;
        for (int j = 0; j < nrcol; j++)
            m[i][j] = s[j];
    }

    bool lin = 0;
    for (int i = 0; i < nrlin; i++)
        lin |= (m[i][0] == '#' && m[i][nrcol - 1] == '#');

    bool col = 0;
    for (int j = 0; j < nrcol; j++)
        col |= (m[0][j] == '#' && m[nrlin - 1][j] == '#');

    if (nrlin == 1 && (!lin))
        col = 0;

    if (nrcol == 1 && (!col))
        lin = 0;

    int ans = 1;
    if (k > 1) {
        if ((!lin) && (!col))
            ans = lgput(sum(nrlin, nrcol), k - 1);
        else if ((!lin) || (!col)) {
            if (col)
                rot(nrlin, nrcol);

            a[0][0] = sum(nrlin, nrcol);
            a[1][0] = MOD - per(nrlin, nrcol);
            a[1][1] = era(nrlin, nrcol);

            inmult(k - 1);

            ans = r[0][0] + r[1][0];
            if (ans >= MOD)
                ans -= MOD;
        }
    }

    std::cout << ans;
}


Measured memory_bytes: 2176