Mathematical expressions in old papers and old technical articles were printed with a typewriter across several lines, which requires a fixed-width (monospace) font to place characters (digits, symbols, and spaces). Consider the following mathematical expression.
$$\left( 1 - \frac{4}{3^2}\right)^2 \times -5 + 6$$
It is printed in the following four lines:
4 2
( 1 - ---- ) * - 5 + 6
2
3
Here - 5 means a unary minus followed by 5. We call such a multi-line expression an ASCII expression.
To help those who want to evaluate ASCII expressions (for example, obtained by OCR from old papers), your task is to write a program that recognizes the structure of an ASCII expression and computes its value.
For simplicity, you may assume that ASCII expressions are built only by the following rules. The syntax is shown in Table H.1.
Table H.1: Rules for building ASCII expressions (similar to Backus-Naur Form). Each box denotes a cell, a rectangular region of characters that corresponds to one terminal or nonterminal symbol. Every syntactically required space character is shown explicitly here as a period ..
(I) expr ::= term | expr.+.term | expr.-.term
(II) term ::= factor | term.*.factor
(III) factor ::= powexpr | fraction | -.factor
digit
(IV) powexpr ::= primary | primary
(V) primary ::= digit | (.expr.)
expr
(VI) fraction ::= ---------
expr
(VII) digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Figure H.1: Top line, base line, and bottom line. Example cells — expr $1-\frac{4}{3^2}$, fraction $\frac{4}{3^2}$, powexpr $3^2$, digit $3$.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, -, *, (, ), and the space character.For example, the negative fraction $-\frac{3}{4}$ is written in three lines:
3
- ---
4
Here the leftmost hyphen is a unary minus operator. Exactly one space is required between the unary minus and the vinculum of the fraction.
The fraction $\frac{3+4 \times -2}{-1-2^2}$ is written in four lines:
3 + 4 * - 2
-------------
2
- 1 - 2
Here the widths of the numerator and denominator cells are 11 and 8, so the vinculum has $2 + \max(11, 8) = 13$ hyphens. The denominator is centered with $\lceil (13 - 8)/2 \rceil = 3$ spaces on the left and $\lfloor (13 - 8)/2 \rfloor = 2$ on the right.
The powexpr $\left(4^2\right)^3$ is written in two lines:
2 3
( 4 )
Here the cell for 2 is one line above the base line of the cell for 4, and the cell for 3 is one line above the base line of the cell for the primary $\left(4^2\right)$.
The input consists of multiple datasets, followed by a line containing a single zero. Each dataset has the following format.
n
str1
str2
.
.
.
strn
$n$ is a positive integer giving the number of the following lines, all of the same length, that represent one ASCII-expression cell. $str_k$ is the $k$-th line of the cell, where every space character has been replaced by a period.
You may assume that $n \le 20$ and that each line has length at most 80.
For each dataset, output on one line a single non-negative integer less than 2011. This integer is the value of the ASCII expression under arithmetic modulo 2011. The output must contain no other characters.
There is no fraction whose divisor is zero or a multiple of 2011.
The powexpr $x^0$ is defined to be 1, and $x^y$ (for a positive integer $y$) is defined as the product $x \times x \times \cdots \times x$ of $y$ copies of $x$.
A fraction $\frac{x}{y}$ is computed as $x$ times the inverse of $y$ modulo 2011, i.e. $x \times \mathrm{inv}(y)$. Since 2011 is prime, the inverse of $y$ ($1 \le y < 2011$) is the unique integer $z$ ($1 \le z < 2011$) with $z \times y \equiv 1 \pmod{2011}$.