import Control.Monad
import Data.List

main = do
    n <- readLn
    formulas <- fmap init $ replicateM n getLine
    mapM_ print $ map calcForm formulas

data Tree a =  Leaf a | Node a (Tree a) (Tree a) deriving Show
isLeaf :: Tree a -> Bool
isLeaf x = case x of
             Leaf _ -> True
             otherwise -> False

calcForm :: String -> Int
calcForm str = calcTree.divCalcTree $ Leaf str

calcTree :: Tree String -> Int
calcTree (Leaf a)            = read a
calcTree (Node c left right) = calc c (calcTree left) (calcTree right)

calc c l r
    | c == "/" = l `div` r
    | c == "*" = l * r
    | c == "-" = l - r
    | c == "+" = l + r

divCalcTree :: Tree String -> Tree String
divCalcTree (Leaf str)
  | check '(' str = calcInParenthesis str
  | check '+' str = sepBy '+' str
  | check '-' str = sepBy '-' str
  | check '*' str = sepBy '*' str
  | check '/' str = sepBy '/' str
  | otherwise     = Leaf str

sepBy :: Char -> String -> Tree String
sepBy c str = Node [c] (divCalcTree left) (divCalcTree right)
    where
        left = Leaf $ takeWhile (/= c) str
        right = Leaf $ tail.dropWhile (/= c) $ str

calcInParenthesis str = divCalcTree (Leaf calcedStr)
    where calcedStr = takeWhile (/= '(') str ++ (show.calcForm $ inParen) ++ (tail.dropWhile (/= ')') $ str)
          inParen   = takeWhile (/= ')').tail.dropWhile (/= '(') $ str

check :: Char -> String -> Bool
check c str = c `elem` str