loop do
	n, m = gets.split.map(&:to_i)
	break if n == 0

	candidates = (1..20).to_a.repeated_permutation(3).to_a
	r = c = s = 0
	(1..n).each do
		line = gets.chomp
		line =~ /^(\.*)/
		indent = $1.size

		candidates.delete_if do |ir, ic, is|
			ir * r + ic * c + is * s != indent
		end
		
		line.scan(/[(){}\[\]]/) do |bracket|
			case bracket
				when ?(; r += 1
				when ?); r -= 1
				when ?{; c += 1
				when ?}; c -= 1
				when ?[; s += 1
				when ?]; s -= 1
			end
		end
	end

	indents = (1..m).map do
		line = gets.chomp
		a = candidates.map {|ir, ic, is| ir * r + ic * c + is * s}.uniq
		indent = (a.size == 1 ? a[0] : -1)

		line.scan(/[(){}\[\]]/) do |bracket|
			case bracket
				when ?(; r += 1
				when ?); r -= 1
				when ?{; c += 1
				when ?}; c -= 1
				when ?[; s += 1
				when ?]; s -= 1
			end
		end

		indent
	end

	puts indents * ' '
end