Stylish is a programming language.
The grammar of Stylish consists of names made of letters, three kinds of brackets, the period (.), and line breaks.
There are three kinds of brackets: round ( ), curly { }, and square [ ]. They must always be used in matching pairs and are properly nested — that is, every opening bracket is matched by a closing bracket of the same kind, and brackets never cross. Unlike other languages, Stylish uses periods (.) instead of spaces for indentation. The following is an example of a Stylish program.
(Welcome.to
.........Stylish)
{Stylish.is
.....[.(a.programming.language.fun.to.learn)
.......]
.....Maybe.[
.......It.will.be.an.official.ICPC.language
.......]
.....}
As the example shows, a Stylish program is indented with periods. The indentation amount of a line is the number of consecutive periods at the beginning of that line.
The indentation of a well-indented Stylish program is determined by an indentation style $(R, C, S)$ with $1 \le R, C, S \le 20$, where $R$, $C$, and $S$ are the indentation amounts for round, curly, and square brackets respectively.
In a well-indented program, the indentation amount of a line equals $R(r_o - r_c) + C(c_o - c_c) + S(s_o - s_c)$, where $r_o, c_o, s_o$ are the numbers of opening round, curly, and square brackets that appear before this line, and $r_c, c_c, s_c$ are the numbers of the corresponding closing brackets. The first line of a well-indented program always has no indentation.
The indentation style of the example above is $(R, C, S) = (9, 5, 2)$. The first line contains one opening round bracket, so the indentation of the second line is $9(1 - 0) + 5(0 - 0) + 2(0 - 0) = 9$. The first four lines contain two opening round brackets, one opening curly bracket, one opening square bracket, and two closing round brackets, so the indentation of the fifth line is $9(2 - 2) + 5(1 - 0) + 2(1 - 0) = 7$.
Given a well-indented Stylish program $P$ and a program $Q$ that is not, write a program that determines the indentation style of $P$ and applies it to $Q$.
The input consists of several test cases. The first line of each test case contains two integers $p$ and $q$ $(1 \le p, q \le 10)$.
The next $p$ lines contain a well-indented program $P$ written by a Stylish master, and the following $q$ lines contain another program $Q$. Every line of both programs has at least 1 character and at most 80 characters. No line of $Q$ starts with a period.
The last line of the input contains two zeros.
For each test case, determine the indentation style of $P$, apply it to $Q$, and print the indentation amount of each line of $Q$, separated by spaces. For any line whose indentation amount cannot be uniquely determined, print -1.