#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

typedef long long i64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pxx;
typedef pair<pxx, pxx> qmat;

qmat operator*(qmat A, qmat B) {
    qmat C;
    i64 a, b, c, d;
    a=A.first.first; b=A.first.second; c=A.second.first; d=A.second.second;
    i64 s, t, u, v;
    s=B.first.first; t=B.first.second; u=B.second.first; v=B.second.second;

    C = qmat(pxx(a*s+b*u, a*t+b*v), pxx(c*s+d*u, c*t+d*v));
    return C;
}

qmat operator%(qmat A, int m) {
    qmat C;
    i64 a, b, c, d;
    a=A.first.first; b=A.first.second; c=A.second.first; d=A.second.second;

    C = qmat(pxx(a%m, b%m), pxx(c%m, d%m));
    return C;
}

qmat operator*=(qmat &A, qmat B) {
    return A=A*B;
}

qmat operator%=(qmat &A, int B) {
    return A=A%B;
}

qmat modpow(qmat A, i64 p, i64 m) {
    qmat res=qmat(pxx(1, 0), pxx(0, 1));
    qmat pow=A;
    while (p) {
        if (p & 1) {
            res *= pow;
            res %= m;
        }
        pow *= pow;
        pow %= m;
        p >>= 1;
    }
    return res % m;
}

int modpow(i64 n, i64 p, i64 m) {
    i64 res=1, pow=n;
    while (p) {
        if (p & 1) {
            res *= pow;
            res %= m;
        }
        pow *= pow;
        pow %= m;
        p >>= 1;
    }
    return res % m;
}

struct Fractal {
    vvi canvas;
    bool is_connectible_h, is_connectible_v;
    i64 a, b, c;
    Fractal(vvi t) {
        int h, w;
        h = t.size();
        w = h? t[0].size():0;
        canvas = t;
        is_connectible_h = is_connectible_v = false;
        int i, j;
        for (i=0; i<h; i++)
            if (canvas[i][0] && canvas[i][w-1]) {
                is_connectible_h = true;
                break;
            }

        for (j=0; j<w; j++)
            if (canvas[0][j] && canvas[h-1][j]) {
                is_connectible_v = true;
                break;
            }

        if (is_connectible_h && is_connectible_v) return;

        a = 0;
        for (i=0; i<h; i++)
            for (j=0; j<w; j++)
                if (canvas[i][j]) a++;

        if (!is_connectible_h && !is_connectible_v) return;
        b = c = 0;
        if (is_connectible_h) {
            for (i=0; i<h; i++) {
                for (j=0; j<w-1; j++)
                    if (canvas[i][j] && canvas[i][j+1]) b++;

                if (canvas[i][w-1] && canvas[i][0]) c++;
            }
        } else {
            for (j=0; j<w; j++) {
                for (i=0; i<h-1; i++)
                    if (canvas[i][j] && canvas[i+1][j]) b++;

                if (canvas[h-1][j] && canvas[0][j]) c++;
            }
        }
    }
    int num_components(i64 K, int MOD=1e9+7) {
        if (is_connectible_h && is_connectible_v) return 1;
        if (!is_connectible_h && !is_connectible_v) {
            return modpow(a, K-1, MOD);
        }
        qmat A=qmat(pxx(a, -b), pxx(0, c));
        qmat V=modpow(A, K-1, MOD);
        return (V.first.first+V.first.second+MOD)%MOD;
    }
};

int main(void) {
    int H, W;
    i64 K;
    cin >> H >> W >> K;

    int i, j;
    vvi s(H, vi(W));
    string t;
    for (i=0; i<H; i++) {
        cin >> t;
        for (j=0; j<W; j++)
            if (t[j]=='#')
                s[i][j] = 1;
    }

    Fractal fractal(s);
    cout << fractal.num_components(K) << endl;

    return 0;
}


Measured memory_bytes: 12032