import Data.Char
import Control.Monad

expression :: String->(String,Int)
expression expr = expression' $ term expr

expression' :: (String,Int)->(String,Int)
expression' ([], n) = ([], n)
expression' (x:xs, n)
    | x=='+'    = expression' (expr', n+n')
    | x=='-'    = expression' (expr', n-n')
    | otherwise = (x:xs, n)
        where (expr', n') = term xs

term :: String->(String,Int)
term expr = term' $ factor expr

term' :: (String,Int)->(String,Int)
term' ([], n) = ([], n)
term' (x:xs, n)
    | x=='*'     = term' (expr', n*n')
    | x=='/'     = term' (expr', n`div`n')
    | otherwise  = (x:xs, n)
        where (expr', n') = factor xs

factor :: String->(String, Int)
factor (x:xs)
    | x=='('    = (tail $ expr1, n1) --ignore ')'
    | otherwise = (expr2, n2)
        where (expr1, n1) = expression xs --ignore '('
              (expr2, n2) = number (x:xs, 0)

number :: (String, Int)->(String, Int)
number ([], n)   = ([], n)
number (x:xs, n) = if isDigit x then number (xs, n*10+(digitToInt x)) else (x:xs, n)

solve :: String->IO ()
solve expr = do
    print (snd $ expression $ takeWhile (/='=') expr)

main :: IO ()
main = do
    n <- readLn
    lexpr <- replicateM n getLine
    mapM_ solve lexpr