{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import qualified Data.Map as M
-- import qualified Data.Char as C
-- import qualified Data.List as L
-- import qualified Data.IntSet as I
-- import Debug.Trace
--------------------------------------------
readInt    = read :: String -> Int
readFloat  = read :: String -> Float
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------

-- ????????°?????? ver.
-- expr   = term   | expr +- term
-- term   = factor | term */ factor
-- factor = number | (expr)

-- ????????°?????? ver.
-- expr   = term   | term (+- expr)
-- term   = factor | factor (*/ term)
-- factor = number | (expr)

type Op = Char
data Tree = Leaf Int | Node Tree Op Tree deriving Show
type Keisan = String -> (Tree -> Tree) -> (Tree,String)

expr :: Keisan
expr ss tr =
  let (t,state) = term ss id in
  if state == "" then (tr t,state)
  else if head state == '+' then expr (tail state) (Node (tr t) '+')
  else if head state == '-' then expr (tail state) (Node (tr t) '-')
  else (tr t,state)

term :: Keisan
term ss tr =
  let (f,state) = factor ss id in
  if state == "" then (tr f,state)
  else if head state == '*' then term (tail state) (Node (tr f) '*')
  else if head state == '/' then term (tail state) (Node (tr f) '/')
  else (tr f,state)

factor :: Keisan
factor ss tr =
  if head ss == '(' then let (e,state) = expr (tail ss) id in (tr e,tail state)
  else let (e,state) = getNumber ss in ((tr . Leaf . read) e,state)
    where
      getNumber = takeWhile2 (\x -> x `elem` ['0'..'9'])

takeWhile2 :: (a -> Bool) -> [a] -> ([a],[a])
takeWhile2 cond l = aux [] l
  where
    aux acc [] = (reverse acc, [])
    aux acc (x:xs)
      | cond x = aux (x:acc) xs
      | otherwise = (reverse acc, x:xs)

solver ss = calc.fst $ expr ss id
-- solver ss = fst $ expr ss id
calc (Leaf a) = a
calc (Node a '+' b) = calc a + calc b
calc (Node a '-' b) = calc a - calc b
calc (Node a '/' b) = calc a `div` calc b
calc (Node a '*' b) = calc a * calc b

main :: IO ()
main = do
  n  <- getInt
  es <- replicateM n getLine
  -- let es = ["0+3*2*2+1=","4-2*3=","4*(8+4+3)=","1-(1-1)-1="]
  mapM_ (print.solver.(takeWhile ('=' /=))) es