ICPC Calculator

No attempts yetTime limit1sMemory limit256 MB

Problem

Mathematics usually fixes the order of operations with parentheses. 7 × (3 + 2) always means multiplying 7 by the result of 3 + 2, and never means adding 2 to the result of 7 × 3. Some people dislike parentheses. The International Counter of Parentheses Council (ICPC) wants a notation without parentheses to become the world standard, and its members keep studying such notations.

Dr. Tsukuba, a member of ICPC, invented a new parenthesis-free notation. In his notation one expression is written on several lines, and each line holds an addition operator +, a multiplication operator *, or one integer. An expression is either a single integer or an operator applied to two or more operands. An integer is written in decimal on one line. An operator application is the line holding the operator, immediately followed by the lines that denote its operands, each of which is again an expression. When an operand is an operator application, that operand takes up several lines.

Expressions nest to any depth, so the notation has to make clear which operator applies to which operands. Every expression is given a nesting level. The top level expression has level 0. When an expression of level nn is an operator application, each of its operands is an expression of level n+1n + 1. The first line of an expression starts with as many periods (.) as its level.

For example, 2 + 3 of ordinary mathematics is written as in Figure 1. An operator can be applied to two or more operands. The operator + means the sum of all operands and the operator * means the product of all operands. Figure 2 is an expression that multiplies 2, 3, and 4. For a longer example, (2 + 3 + 4) × 5 is written as in Figure 3, and (2 + 3) × 4 × 5 is written as in Figure 4.

+
.2
.3

Figure 1: 2 + 3

*
.2
.3
.4

Figure 2: an expression that multiplies 2, 3, and 4

*
.+
..2
..3
..4
.5

Figure 3: (2 + 3 + 4) × 5

*
.+
..2
..3
.4
.5

Figure 4: (2 + 3) × 4 × 5

Write a program that computes the value of an expression written in Dr. Tsukuba's notation.

Input

The input holds several datasets. Each dataset starts with a line holding a positive integer nn, followed by nn lines that denote one expression in Dr. Tsukuba's notation.

In every expression of the input each integer is a single digit, and one expression holds at most nine integers. Every input expression is valid in Dr. Tsukuba's notation. The input holds no extra characters such as spaces or empty lines.

A line holding a single zero follows the last dataset.

Output

For each dataset, print one line holding the value of the given expression as a single integer.