import Control.Applicative ((<$>), (<*>), (*>), (<*))
import Control.Monad
import Data.List
import Text.Parsec
import Text.Parsec.String

main :: IO ()
main = do
  n <- getl toInt
  map solve <$> replicateM n getLine >>= mapM_ print

solve :: String -> Int
solve cs = either (const 0) id $ parse (kagen <* char '=') "" cs

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

num :: Parser Int
num = read <$> many1 digit

joujo :: Parser Int
joujo = do
  x <- numpar
  fs <- many (muldiv <$> (char '*' <|> char '/') <*> numpar)
  return $ foldl (flip ($)) x fs

muldiv :: Char -> Int -> Int -> Int
muldiv op x
  | op == '*' = (* x)
  | otherwise = (`div` x)

kagen :: Parser Int
kagen = do
  x <- joujo
  fs <- many (addsub <$> (char '+' <|> char '-') <*> joujo)
  return $ foldl (flip ($)) x fs

addsub :: Char -> Int -> Int -> Int
addsub op x
  | op == '+' = (+ x)
  | otherwise = subtract x
                
numpar :: Parser Int
numpar = num <|> (char '(' *> kagen <* char ')')