#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 4e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

const int P = 1e9 + 7;
int add(int a, int b)
{
    return a + b >= P ? a + b - P : a + b;
}
int mul (int a, int b)
{
    return (a * b) % P;
}
int bpow(int a, int n)
{
    int res = 1;
    while (n)
    {
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}
int rev(int x)
{
    return bpow(x, P - 2);
}
int divi(int a, int b)
{
    return mul(a, rev(b));
}
int sub(int a, int b)
{
    return add(a, P - b);
}
using line = vector <int>;
using matrix = vector <line>;
matrix mul(matrix a, matrix b)
{
    int n = a.size(), k = a[0].size(), kk = b.size(), m = b[0].size();
    assert(k == kk);
    matrix c(n, line(m));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            for (int t = 0; t < k; ++t)
                c[i][j] = add(c[i][j], mul(a[i][t], b[t][j]));
    return c;
}
matrix bpow(matrix a, int n)
{
    matrix res(a.size(), line(a.size()));
    for (int i = 0; i < a.size(); ++i)
        res[i][i] = 1;
    while (n)
    {
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}


signed main()
{
    Start();
    int n, m, k;
    cin >> n >> m >> k;
    if (k == 0)
        return cout << 1, 0;
    vector <vector <char>> a(n, vector <char> (m));
    cin >> a;
    int hor = 0, ver = 0;
    for (int i = 0; i < n; ++i)
        hor += (a[i][0] == '#' && a[i][m - 1] == '#');
    for (int i = 0; i < m; ++i)
        ver += (a[0][i] == '#' && a[n - 1][i] == '#');
    int cnt = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cnt += (a[i][j] == '#');
    if (!hor && !ver)
        return cout << bpow(cnt, k - 1), 0;
    if (hor && ver)
        return cout << 1, 0;
    if (ver)
    {
        vector <vector <char>> b(m, vector <char> (n));
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                b[j][i] = a[i][j];
        swap(n, m);
        swap(ver, hor);
        a = b;
    }
    int adj = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j + 1 < m; ++j)
            adj += (a[i][j] == a[i][j + 1] && a[i][j] == '#');
    matrix f = {{cnt, P - adj},
                {0  , hor }};
    f = bpow(f, k - 1);
    cout << add(f[0][0], f[0][1]);
    return 0;
}
/*
 * 
 * comp = comp' * black - hor' * adj
 * hor  = comp' * 0     + hor' * prm_hor
 *
 */


Measured memory_bytes: 3328