//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n, d;
    cin >> m >> n >> d;
    while(m or n or d) {
        vvi s(n, vi(m));
        rep(i, n) rep(j, m) {
            cin >> s[i][j];
        }

        auto num = [&](int i, int j) {
            return i*m + j;
        };

        vector<bitset<625> > bits(625);
        rep(i, n) rep(j, m) {
            bitset<625> now(0);
            now[num(i, j)] = 1;
            rep(k, n) rep(l, m) if(abs(k-i) + abs(l-j) == d) {
                now[num(k, l)] = 1;
            }
            int x = -1;
            for(int k = 624; k >= 0; k--) {
                if(now.test(k) and bits[k].test(k)) {
                    now ^= bits[k];
                }
                if(now.test(k)) chmax(x, k);
            }
            if(x == -1) continue;
            for(int k = 624; k > x; k--) {
                if(bits[k].test(x)) {
                    bits[k] ^= now;
                }
            }
            bits[x] = now;
        }

        bitset<625> S(0);
        rep(i, n) rep(j, m) {
            if(s[i][j]) {
                S.set(num(i, j));
            }
        }
        //cout << S << endl;
        for(int i = 624; i >= 0; i--) {
            //cout << bits[i] << endl;
            if(S.test(i) and bits[i].test(i)) {
                S ^= bits[i];
            }
        }

        cout << (S == bitset<625>(0)) << '\n';
        cin >> m >> n >> d;
    }
}
