#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  constexpr ModInt() : v(0) {}
  constexpr ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
using Mint = ModInt<998244353>;

template<unsigned P, unsigned g = 6420> void ntt(V< ModInt<P> >& a, bool inv = false) {
  int n = a.size();
  assert(__builtin_popcount(n) == 1);
  int j = 0;
  for (int i = 1; i < n; ++i) {
    int w = n >> 1;
    while (j >= w) j -= w, w >>= 1;
    j += w;
    if (i < j) swap(a[i], a[j]);
  }
  assert((P - 1) % n == 0);
  auto xi = ModInt<P>(g).pow((P - 1) / n);
  if (inv) xi = xi.inv();
  for (int k = 0; 1 << k < n; ++k) {
    const int w = 1 << k;
    const auto dt = xi.pow(n >> k + 1);
    for (int s = 0; s < n; s += 2 * w) {
      ModInt<P> t = 1;
      for (int i = s; i < s + w; ++i) {
        auto p = a[i], q = a[i + w] * t;
        a[i] = p + q, a[i + w] = p - q;
        t *= dt;
      }
    }
  }
}
template<unsigned P, unsigned g = 6420> V< ModInt<P> > multiply(const V< ModInt<P> >& a, const V< ModInt<P> >& b) {
  if (a.empty() or b.empty()) return {};
  int sz = a.size() + b.size() - 1, n = 1 << __lg(2 * sz - 1);
  auto _a = a, _b = b;
  _a.resize(n), _b.resize(n);
  ntt<P, g>(_a), ntt<P, g>(_b);
  for (int i = 0; i < n; ++i) _a[i] *= _b[i];
  ntt<P, g>(_a, true);
  _a.resize(sz);
  const auto inv_n = ModInt<P>(n).inv();
  for (auto&& e : _a) e *= inv_n;
  return _a;
}

template<class T> V<T> operator*(const VV<T>& A, const V<T>& x) {
  assert(A[0].size() == x.size());
  V<T> res(A.size());
  for (int i = 0; i < (int) A.size(); ++i) {
    res[i] = inner_product(begin(A[i]), end(A[i]), begin(x), (T) 0);
  }
  return res;
}
template<class T> VV<T> operator*(const VV<T>& A, const VV<T>& B) {
  assert(A[0].size() == B.size());
  VV<T> res(A.size(), V<T>(B[0].size()));
  for (int i = 0; i < (int) A.size(); ++i) for (int k = 0; k < (int) A[0].size(); ++k) for (int j = 0; j < (int) B[0].size(); ++j) {
    res[i][j] += A[i][k] * B[k][j];
  }
  return res;
}
template<class T> VV<T>& operator*=(VV<T>& A, const VV<T>& B) { return A = A * B; }
template<class T> VV<T> I(int n) {
  VV<T> res(n, V<T>(n));
  for (int i = 0; i < n; ++i) res[i][i] = 1;
  return res;
}
template<class T> VV<T> pow(VV<T> A, lint n) {
  auto res = I<T>(A.size());
  while (n) {
    if (n & 1) res *= A;
    A *= A;
    n >>= 1;
  }
  return res;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int h, w, k; cin >> h >> w >> k;
  h = 1 << h, w = 1 << w;
  VV<Mint> c(h, V<Mint>(w));
  VV<Mint> t(h, V<Mint>(w));
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
    int T; cin >> T;
    c[i][j] = (int)(T != -1);
    t[i][j] = T == -1 ? 0 : T;
  }
  VV<Mint> g(h, V<Mint>(w));
  VV<Mint> tg(h, V<Mint>(w));
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
    int G; cin >> G;
    g[i][j] = G == -1 ? 0 : G;
    tg[i][j] = t[i][j] * g[i][j];
  }

  auto ntt2D = [&](VV<Mint>& v, bool inv = false) -> void {
    for (auto&& e : v) {
      ntt(e, inv);
    }
    for (int j = 0; j < w; ++j) {
      V<Mint> a(h);
      for (int i = 0; i < h; ++i) {
        a[i] = v[i][j];
      }
      ntt(a, inv);
      for (int i = 0; i < h; ++i) {
        v[i][j] = a[i];
      }
    }
    if (inv) {
      for (auto&& e : v) for (auto&& f : e) {
        f /= h * w;
      }
    }
  };

  ntt2D(c);
  ntt2D(t);
  ntt2D(tg);
  ntt2D(g);

  VV<Mint> res(h, V<Mint>(w));
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
    V<Mint> dp(5);
    dp[0] = 1;
    VV<Mint> A(5, V<Mint>(5));
    A[0][0] = A[1][1] = A[2][2] = A[3][3] = c[i][j];
    A[1][0] = t[i][j];
    A[2][0] = tg[i][j], A[2][1] = g[i][j];
    A[3][0] = g[i][j];
    A[4][2] = A[4][4] = 1;
    dp = pow(A, k + 1) * dp;
    res[i][j] = dp[4];
  }

  ntt2D(res, true);
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
    cout << res[i][j] << " \n"[j == w - 1];
  }
}


Measured memory_bytes: 8132