import Data.Char
import Control.Monad
import Debug.Trace

findChar :: Char -> String -> String
findChar c (x:xs) = if c==x then [x] else x:findChar c xs

findChar2 :: Char -> String -> (String,String)
findChar2 c str = (init resstr, drop len str)
    where resstr = findChar c str
          len = length resstr

findCharRev :: Char -> String -> String
findCharRev c str = reverse $ drop len (c:rstr)
    where rstr = reverse str
          len = length $ findChar c rstr

isDigitS :: String -> Bool
isDigitS (x:xs) = if x=='-' then isDigitS xs else and $ map isDigit (x:xs)

evalDigit :: String -> Int
evalDigit (x:xs) = if x=='-' then (-1)*(evalDigit xs) else read (x:xs) :: Int

evalOp :: (Int->Int->Int)->Char->String->Int
evalOp op opc expr = op (evalExpr expr1) (evalExpr expr2)
    where (expr1, expr2) = findChar2 opc expr

evalPrnt :: String -> Int
evalPrnt expr = evalExpr $ expr1++(show $ evalExpr ('(':expr2))
    where (expr1, expr2) = findChar2 '(' expr

evalExpr :: String -> Int
evalExpr (x:xs)
    | x=='('          = evalExpr $ init $ findCharRev ')' xs
    | isDigitS (x:xs) = evalDigit (x:xs)
    | otherwise       = 
        if      elem '(' (x:xs) then evalPrnt (x:xs)
        else if elem '+' (x:xs) then evalOp (+) '+' (x:xs)
        else if elem '-' (x:xs) then evalOp (-) '-' (x:xs)
        else if elem '*' (x:xs) then evalOp (*) '*' (x:xs)
        else if elem '/' (x:xs) then evalOp div '/' (x:xs)
        else error "Error"

solve :: String -> Int
solve expr = evalExpr $ takeWhile (\c->c/='=') expr

main = do
    n <- readLn
    l_expr <- replicateM n getLine
    mapM_ print $ map (solve)  l_expr
 
    