// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e3 + 5;
const int MOD = 1e9 + 7;

int H, W;
LL K;
char S[MAXN][MAXN];

void input()
{
    read(H); read(W); read(K);
    for (int i = 1; i <= H; ++i) {
        scanf("%s", S[i] + 1);
    }
}

struct Mat2x2 {
    LL a, b, c, d;

    Mat2x2(): a(0), b(0), c(0), d(0) { }
    Mat2x2(LL a_, LL b_, LL c_, LL d_): a(a_ % MOD), b(b_ % MOD), c(c_ % MOD), d(d_ % MOD) { }
    friend Mat2x2 operator* (const Mat2x2 &a, const Mat2x2 &b)
    {
        return Mat2x2(a.a * b.a + a.b * b.c, a.a * b.b + a.b * b.d,
                      a.c * b.a + a.d * b.c, a.c * b.b + a.d * b.d);
    }
};

LL fpm(LL base, LL exp)
{
    LL ret = 1;
    for (; exp; exp >>= 1) {
        if (exp & 1)
            (ret *= base) %= MOD;
        (base *= base) %= MOD;
    }
    return ret;
}

Mat2x2 fpm(Mat2x2 base, LL exp)
{
    Mat2x2 ret(1, 0, 0, 1);
    for (; exp; exp >>= 1) {
        if (exp & 1)
            ret = ret * base;
        base = base * base;
    }
    return ret;
}

void solve()
{
    if (K <= 1) {
        puts("1");
        return;
    }

    int cnt = 0;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            cnt += (S[i][j] == '#');
        }
    }

    int hflag = 0, vflag = 0;
    for (int i = 1; i <= H; ++i) {
        hflag += (S[i][1] == '#' && S[i][W] == '#');
    }
    for (int i = 1; i <= W; ++i) {
        vflag += (S[1][i] == '#' && S[H][i] == '#');
    }
    if (hflag && vflag) {
        puts("1");
        return;
    }
    if (!hflag && !vflag) {
        printf("%lld\n", fpm(cnt, K - 1));
        return;
    }

    int con = hflag + vflag, dec = 0;
    if (hflag) {
        for (int i = 1; i <= H; ++i) {
            for (int j = 1; j < W; ++j) {
                dec += (S[i][j] == '#' && S[i][j + 1] == '#');
            }
        }
    } else {
        for (int i = 1; i < H; ++i) {
            for (int j = 1; j <= W; ++j) {
                dec += (S[i][j] == '#' && S[i + 1][j] == '#');
            }
        }
    }

    // printf("cnt=%d, len=%d, con=%d, dec=%d\n", cnt, len, con, dec);

    Mat2x2 mat(cnt, MOD - dec,
                 0, con);
    mat = fpm(mat, K - 2);
    int ans = (mat.a * (cnt - dec) + mat.b * con) % MOD;

    printf("%d\n", ans);
}

int main()
{
#ifdef __DEBUG
    freopen("F.in", "r", stdin);
    freopen("F.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 看蓬门秋草，年年破巷，疏窗细雨，夜夜孤灯。
//     -- 郑板桥《沁园春·恨》


Measured memory_bytes: 1280