import Control.Monad
import Data.List
main = readLn >>= main'
    where
        main' 0 = return ()
        main' n = replicateM n getLine >>= print . solve >> main

data Elem = Val { val :: Int } | Sum | Prod
    deriving (Show, Eq)

solve :: [String] -> Int
solve = consumeAll . foldl' ff ([], [])
    where
        ff (acc, ds) x
            | null ds || head ds <= d = (next : acc, d : ds)
            | otherwise = ff (acc', ds') x
            where
                d = depth x
                x' = drop d x
                next
                    | x' == "*" = Prod
                    | x' == "+" = Sum
                    | otherwise = Val $ read x'
                (acc', ds') = consume (head ds) acc ds

        depth = inner 0
            where
                inner n (x : xs)
                    | x == '.' = inner (n + 1) xs
                    | otherwise = n

        consume 0 vs ds = (vs, ds)
        consume n vs ds
            | v' == Sum = (sum' ys : vs', ds')
            | otherwise = (product' ys : vs', ds')
            where
                (ys, v' : vs') = splitAt c vs
                ds' = drop c ds
                c = count ds
                count = inner 0
                    where
                        inner m (x : xs)
                            | n == x = inner (m + 1) xs
                            | otherwise = m
                        inner m _ = m

                sum' = Val . foldl' (\acc x -> acc + val x) 0
                product' = Val . foldl' (\acc x -> acc * val x) 1

        consumeAll (vvs@(v : _), dds@(d : _))
            | d == 0 = val v
            | otherwise = consumeAll (vs, ds)
            where
                (vs, ds) = consume d vvs dds