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 $ 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 :: String -> Tree String
divCalcTree str
  | check '(' str = divCalcTree $ 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 = takeWhile (/= c) str
        right = tail.dropWhile (/= c) $ str

calcInParenthesis :: String -> String
calcInParenthesis str = if '(' `elem` str then calcInParenthesis calcedStr
                                          else str
                                              where
                                                  calcedStr = before ++ (show.calcForm $ mid) ++ after
                                                  ([before,after],mid) = cutParen str

cutParen :: String -> ([String], String)
cutParen str = ([before,after],init mid)
    where
        (before, next) = span (/= '(') str
        (mid,after)    = betweenParen next

betweenParen :: String -> (String, String)
betweenParen str = between  [] 1 (tail str)
    where
        between list n (x:xs)
          | n == 0 = (reverse list, (x:xs))
          | x == '(' = between (x:list) (n+1) xs
          | x == ')' = between (x:list) (n-1) xs
          | otherwise = between (x:list) n xs


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