#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
class modulo_int {
public:
  static constexpr int mod = T::value;
  static_assert(mod > 0, "mod must be positive");
private:
  long long value;
  constexpr void normalize() {
    value %= mod;
    if (value < 0) value += mod;
  }
public:
  constexpr modulo_int(long long value_ = 0): value(value_) { normalize(); }
  constexpr modulo_int operator - () const { return modulo_int(mod - value); }
  constexpr modulo_int operator ~ () const { return power(mod - 2); }
  constexpr long long operator () () const { return value; }
  constexpr modulo_int operator + (const modulo_int &rhs) const { return modulo_int(*this) += rhs; }
  constexpr modulo_int &operator += (const modulo_int &rhs) {
    if ((value += rhs.value) >= mod) value -= mod;
    return (*this);
  }
  constexpr modulo_int operator - (const modulo_int &rhs) const { return modulo_int(*this) -= rhs; }
  constexpr modulo_int &operator -= (const modulo_int &rhs) {
    if ((value += mod - rhs.value) >= mod) value -= mod;
    return (*this);
  }
  constexpr modulo_int operator * (const modulo_int &rhs) const { return modulo_int(*this) *= rhs; }
  constexpr modulo_int &operator *= (const modulo_int &rhs) {
    (value *= rhs.value) %= mod;
    return (*this);
  }
  constexpr modulo_int operator / (const modulo_int &rhs) const { return modulo_int(*this) /= rhs; }
  constexpr modulo_int &operator /= (const modulo_int &rhs) {
    return (*this) *= ~rhs;
  }
  constexpr bool operator == (const modulo_int &rhs) const {
    return value == rhs();
  }
  constexpr bool operator != (const modulo_int &rhs) const {
    return value != rhs();
  }
  constexpr modulo_int power (unsigned long long pow) const {
    modulo_int result(1), mult(*this);
    while (pow > 0) {
      if (pow & 1) result *= mult;
      mult *= mult;
      pow >>= 1;
    }
    return result;
  }
  friend std::istream &operator >> (std::istream &stream, modulo_int &lhs) {
    stream >> lhs.value;
    lhs.normalize();
    return stream;
  }
  friend std::ostream &operator << (std::ostream &stream, const modulo_int &rhs) {
    return stream << rhs.value;
  }
};

template <class T>
class matrix: public std::vector<std::vector<typename T::value_type>> {
public:
  using value_type = typename T::value_type;
  using addition = typename T::addition;
  using multiplication = typename T::multiplication;

private:
  addition add;
  multiplication mult;

public:
  int height, width;

  matrix(): add(addition()), mult(multiplication()) { }
  matrix(int height_, int width_, const value_type &initial_ = addition().identity):
    add(addition()), mult(multiplication()),
    height(height_), width(width_),
    std::vector<std::vector<value_type>>(height_, std::vector<value_type>(width_, initial_))
  { }
  matrix(const std::vector<std::vector<value_type>> &data_):
    add(addition()), mult(multiplication()),
    height(data_.size()), width(data_.front().size()),
    std::vector<std::vector<value_type>>(data_)
  { }

  matrix operator + (const matrix &rhs) const { return matrix(*this) += rhs; }
  matrix& operator += (const matrix &rhs) { 
    for (int i = 0; i < height; ++i) {
      for (int j = 0; j < width; ++j) {
        (*this)[i][j] = add((*this)[i][j], rhs[i][j]);
      }
    }
    return *this;
  }

  matrix& operator *= (const matrix &rhs) { *this = (*this) * rhs; return *this; }
  matrix operator * (const matrix &rhs) const {
    matrix res(height, rhs.width);
    for (int i = 0; i < height; ++i) {
      for (int j = 0; j < rhs.width; ++j) {
        for (int k = 0; k < width; ++k) {
          res[i][j] = add(res[i][j], mult((*this)[i][k], rhs[k][j]));
        }
      }
    }
    return res;
  }

  matrix operator * (const value_type &rhs) const { return matrix(*this) *= rhs; }
  matrix& operator *= (const value_type &rhs)  { 
    for (int i = 0; i < height; ++i) {
      for (int j = 0; j < width; ++j) {
        (*this)[i][j] = mult((*this)[i][j], rhs);
      }
    }
    return *this;
  }

  matrix power(unsigned long long pow) const {
    matrix res(height, width), use(*this);
    for (int i = 0; i < height; ++i) {
      res[i][i] = mult.identity;
    }
    while (pow > 0) {
      if (pow & 1) {
        res *= use;
      }
      use *= use;
      pow >>= 1;
    }
    return res;
  }

};

template <class T>
struct number {
  using value_type = T;
  struct addition {
    value_type identity = 0;
    value_type operator () (const value_type &x, const value_type &y) const {
      return x + y;
    }
  };
  struct multiplication {
    value_type identity = 1;
    value_type operator () (const value_type &x, const value_type &y) const {
      return x * y;
    }
  };
};

using modint = modulo_int<std::integral_constant<int, 1000000007>>;

int main() {
  int H, W;
  long long K;
  std::cin >> H >> W >> K;
  if (K == 0) {
    std::cout << "0\n";
    return 0;
  }
  std::vector<std::string> grid(H);
  for (auto &s: grid) {
    std::cin >> s;
  }
  int vert = 0;
  for (int j: range(0, W)) {
    if (grid[0][j] == '#' && grid[H - 1][j] == '#') {
      ++vert;
    }
  }
  int side = 0;
  for (int i: range(0, H)) {
    if (grid[i][0] == '#' && grid[i][W - 1] == '#') {
      ++side;
    }
  }
  int black = 0;
  for (const auto &s: grid) {
    black += std::count(s.cbegin(), s.cend(), '#');
  }
  if (vert > 0 && side > 0) {
    std::cout << "1\n";
  }
  else if (vert > 0) {
    int connect = 0;
    for (int j: range(0, W)) {
      for (int i: range(0, H - 1)) {
        if (grid[i][j] == '#' && grid[i + 1][j] == '#') {
          ++connect;
        }
      }
    }
    matrix<number<modint>> start({ { 1, connect } }), pow({ { black, 0, }, { -1, vert } });
    std::cout << (start * pow.power(K - 1))[0][0] << '\n';
  }
  else if (side > 0) {
    int connect = 0;
    for (int i: range(0, H)) {
      for (int j: range(0, W - 1)) {
        if (grid[i][j] == '#' && grid[i][j + 1] == '#') {
          ++connect;
        }
      }
    }
    matrix<number<modint>> start({ { 1, connect } }), pow({ { black, 0, }, { -1, side } });
    std::cout << (start * pow.power(K - 1))[0][0] << '\n';
  }
  else {
    std::cout << modint(black).power(K - 1) << '\n';
  }
  return 0;
}


Measured memory_bytes: 1408