class SparseMatrix
	def initialize(m, n)
		@m, @n = m, n
		@rows = (1..m).map{ Hash.new(0) }
		@cols = (1..n).map{ Hash.new(0) }
	end

	def [](i)
		@rows[i]
	end

	def rank
		save = Marshal.load(Marshal.dump(self))
		rank = 0
		j = 0
		(0..@m-1).each{|i|
			pivot_idx = nil
			j += 1 until j >= @n || pivot_idx = @rows.index{|row| row[j] && row[j] != 0}
			break if j >= @n
			rank += 1

			pivot_row = @rows.delete_at(pivot_idx)
			a = pivot_row[j]
			
			@rows.each{|row|
				b = row[j]
				if b && b != 0
					r = b / a
					pivot_row.each{|k, val|
						row[k] -= r * val
						row.delete(k) if row[k] == 0
					}
				end
			}

			j += 1
		}		
		@rows = save.rows
		rank
	end

	def []=(i, j, x)
		@rows[i][j] = x
		@cols[j][i] = x
	end

	def *(other)
		m = SparseMatrix.new(@m, @n)
		(0..@m-1).each{|i|
			(0..@n-1).each{|j|
				row = @rows[i]
				col = other.cols[j]
				row, col = col, row if row.size > col.size
				sum = 0
				row.each{|k, x|
					sum += x * col[k] if col[k]
				}
				m[i, j] = 1 if sum % 2 > 0
			}
		}
		m			
	end

	attr_reader :rows, :cols
end

def exp(n, k, mod = nil)
	x = SparseMatrix.new(n.rows.size, n.cols.size)
	(0..n.rows.size-1).each{|i|
		x[i,i] = 1
	}
	r = n
	while k > 0
		x *= r if k & 1 == 1
		r *= r		
		if mod
			x %= mod
			r %= mod
		end
		k >>= 1
	end
	x
end

n = gets.to_i
mat = SparseMatrix.new(n, n)
a = (0..n-1).map { gets.split.map &:to_i }
(0..n-1).each{|i|
	(0..n-1).each{|j|
		mat[i, j] = 1 if a[i][j] == 1		
	}
}
	
v = (1..n).map{ gets.to_i }
t = gets.to_i

mat = exp(mat, t)

a = [0] * n
(0..n-1).each{|i|
	(0..n-1).each{|j|
		a[i] |= (1 << j) if mat[i][j] == 1
	}
}
(0..n-1).each{|i|
	a[i] |= (v[i] << n)
}

require 'set'
used = Set.new
(0..n-1).each{|i|
	j = (0..n-1).find{|j| a[j][i] == 1 && !used.include?(j)}
	next if !j
	used << j
	(0..n-1).each{|k|
		next if k == j || a[k][i] == 0
		a[k] ^= a[j]
	}
}

if a.include?(1 << n) 
	puts 'none'
elsif a.include?(0)
	puts 'ambiguous'
else
	puts a.sort_by{|x| x & ((1 << n) -1 )}.map{|x| x >> n}.join(" ")
end