#include <bits/stdc++.h>
using namespace std;

int N;
bool full;

vector<vector<int>> prod(const vector<vector<int>>& a, const vector<vector<int>>& b) {
	vector<vector<int>> res(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				res[i][k] ^= b[i][j] & a[j][k];
			}
		}
	}
	return res;
}

vector<vector<int>> Pow(vector<vector<int>> a, int x) {
	vector<vector<int>> res(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		res[i][i] = 1;
	}
	while (x) {
		if (x & 1) {
			res = prod(res, a);
		}
		a = prod(a, a);
		x >>= 1;
	}
	return res;
}

vector<int> solve(vector<vector<int>>& a, vector<int> v) {
	full = true;
	for (int i = 0; i < N; i++) {
		int id = -1;
		for (int j = i; j < N; j++) {
			if (a[j][i]) {
				id = j;
				break;
			}
		}
		if (id == -1) {
			full = false;
			continue;
		}
		if (id != i) {
			swap(a[i], a[id]);
			swap(v[i], v[id]);
		}
		for (int j = i + 1; j < N; j++) {
			if (a[j][i]) {
				for (int k = i; k < N; k++) {
					a[j][k] ^= a[i][k];
				}
				v[j] ^= v[i];
			}
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (a[i][i] == 0) continue;
		for (int j = 0; j < i; j++) {
			if (a[j][i]) {
				for (int k = i; k < N; k++) {
					a[j][k] ^= a[i][k];
				}
				v[j] ^= v[i];
			}
		}
	}
	return v;
}

int main()
{
	int T;
	cin >> N;
	vector<vector<int>> a(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> a[i][j];
		}
	}
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	cin >> T;
	a = Pow(a, T);
	v = solve(a, v);
	if (!full) {
		bool none = false;
		for (int i = 0; i < N; i++) {
			bool flag = true;
			for (int j = 0; j < N; j++) {
				if (a[i][j]) {
					flag = false;
					break;
				}
			}
			if (flag && v[i]) {
				none = true;
				break;
			}
		}
		cout << (none ? "none" : "ambiguous") << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		cout << v[i] << " \n"[i + 1 == N];
	}
	return 0;
}