#include <bits/stdc++.h>

const int N = 1e3 + 5;
const int P = 1e9 + 7;
typedef long long LL;
using namespace std;

struct mat33 {
    LL a[3][3];
    inline mat33() { memset(a, 0, sizeof(a)); }
    inline LL &operator () (int x, int y) { return a[x][y]; }
    inline mat33 operator * (mat33 &w) {
        mat33 res = mat33();
        for(int i = 0; i < 3; i++) {
            for(int k = 0; k < 3; k++) {
                for(int j = 0; j < 3; j++) {
                    res(i, k) += a[i][j] * w(j, k) % P;
                }
                res(i, k) %= P;
            }
        }
        return res;
    }
} ;

int H, W, Hflag, Wflag;
LL K;
char c[N][N];
LL X2, Y2, Z2, S, T, U, ans = 0;

inline void trans() {
    for(int i = 1; i <= max(H, W); i++) 
        for(int j = 1; j <= max(H, W) ; j++)
            if(i > j) swap(c[i][j], c[j][i]);
    swap(H, W);
    swap(Hflag, Wflag);
}

inline mat33 ksm(mat33 base, LL x) {
    mat33 res = mat33();
    res(0, 0) = res(1, 1) = res(2, 2) = 1;
    while(x) {
        if(x & 1ll) res = res * base;
        x >>= 1; base = base * base;
    }
    return res;
}

inline void init() {
    for(int i = 1; i <= H; i++)
        for(int j = 1; j <= W; j++) {
            scanf(" %c", &c[i][j]);
            if(c[i][j] == '#') S++;
        }
    for(int i = 1; i <= H; i++) {
        if(c[i][1] == '#' && c[i][W] == '#') {
            Hflag = true;
            break;
        }
    }
    for(int j = 1; j <= W; j++) {
        if(c[1][j] == '#' && c[H][j] == '#') {
            Wflag = true;
            break;
        }
    }
    if(Hflag + Wflag == 0) {
        mat33 res = mat33();
        res(0, 0) = S;
        res = ksm(res, K - 1);
        printf("%lld\n", res(0, 0));
    }
    else if(Hflag + Wflag == 2) {
        printf("1\n");
    }
    else {
        if(Wflag == true) trans();
        for(int i = 1; i <= H; i++) {
            int cnt = 0, headflag = false;
            for(int j = 1; j <= W + 1; j++) {
                if(c[i][j] == '#') { 
                    cnt++;
                }
                else {
                    if(cnt) {
                        X2++;
                        if(cnt == W) {
                            X2--;
                            Z2++;
                            T -= 2;
                        }
                        else {
                            if(j == cnt + 1) headflag = true;
                            if(j == W + 1) if(headflag) X2 -= 2, Y2 += 2;
                        }
                        T += cnt + 1;
                    }
                    cnt = 0;
                }
            }
        }
        LL _2 = (P + 1) / 2;
        mat33 base = mat33(), res  = mat33();
        base(0, 0) = S;
        base(0, 1) = (T - Y2) * _2 % P;
        base(0, 2) = X2;
        base(1, 1) = Y2 / 2 + Z2;
        base(1, 2) = Y2;
        base(2, 2) = Z2;
        res(0, 0) = X2;
        res(1, 0) = Y2;
        res(2, 0) = Z2;
        res = ksm(base, K - 2) * res;
        printf("%lld\n", (res(0, 0) + res(1, 0) + res(2, 0)) % P);
        /*
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) printf("%lld ", ksm(base , K - 2)(i, j)); 
            printf("\n");
        }
        printf("%lld %lld %lld\n", res(0, 0), res(1, 0), res(2, 0));
        printf("%lld %lld %lld | %lld %lld \n", X2, Y2, Z2, S, T);
        */   
    }
    //printf("%lld\n", Hflag + Wflag);
}

int main() {
    cin >> H >> W >> K;
    if(K <= 1) printf("1\n");
    else init();
    return 0;
}

Measured memory_bytes: 1280