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

findPrnth n depth (x:xs)
    | x==")"    = if depth==0 then n else findPrnth (n+1) (depth-1) xs
    | x=="("    = findPrnth (n+1) (depth+1) xs
    | otherwise = findPrnth (n+1) depth xs

crrspPrnth expr = (take i expr, drop (i+1) expr)
    where i = findPrnth 0 0 expr

isDigitS :: String -> Bool
isDigitS expr = and $ map isDigit expr

data Op = Plus | Minus | Mult |Divide deriving (Eq, Ord, Show)
data Tree =  Empty | Leaf Int | Parentheses Tree | Node Op Tree Tree deriving (Eq, Show)

parseExpr :: [String] -> Tree -> Tree
parseExpr [] tree = tree
parseExpr (x:xs) tree
    | isDigitS x = parseExpr xs $ number x tree
    | tree==Empty && x=="-" = parseExpr xs $ Node Minus (Leaf 0) Empty
    | x=="+"                = parseExpr xs $ plus tree Plus
    | x=="-"                = parseExpr xs $ plus tree Minus
    | x=="*"                = parseExpr xs $ mult tree Mult
    | x=="/"                = parseExpr xs $ mult tree Divide
    | x=="("                = parseExpr e2 $ parentheses e1 tree
    | otherwise             = tree
        where (e1, e2) = crrspPrnth xs

parentheses :: [String] -> Tree -> Tree
parentheses expr Empty = Parentheses $ parseExpr expr Empty
parentheses expr (Node op t1 t2)
    | t2 == Empty = Node op t1 $ Parentheses $ parseExpr expr Empty
    | otherwise   = Node op t1 $ parentheses expr t2

number :: String -> Tree -> Tree
number x Empty = Leaf $ (read x :: Int)
number x (Node o t1 t2)
    | t2 == Empty = Node o t1 (Leaf $ (read x :: Int))
    | otherwise   = Node o t1 $ number x t2

plus :: Tree -> Op -> Tree
plus tree o = Node o tree Empty

mult :: Tree -> Op -> Tree
mult (Leaf t2) op = Node op (Leaf t2) Empty
mult (Parentheses t2) op = Node op (Parentheses t2) Empty
mult (Node op1 t1 t2) op2 
    | op1 == Plus || op1 == Minus  = Node op1 t1 $ mult t2 op2
    | op1 == Mult || op1 == Divide = Node op2 (Node op1 t1 t2) Empty

tokens :: String -> [String]
tokens "" = []
tokens (x:xs) 
    | elem x ['+','-','*','/','(',')'] = [x]:(tokens xs)
    | otherwise                        = dig:(tokens $ drop len (x:xs))
        where dig = takeWhile isDigit (x:xs)
              len = length dig

evalExpr :: Tree -> Int
evalExpr (Leaf t) = t
evalExpr (Parentheses t) = evalExpr t
evalExpr (Node o t1 t2) 
    | o == Plus   = v1 + v2
    | o == Minus  = v1 - v2
    | o == Mult   = v1 * v2
    | o == Divide = v1 `div` v2
        where v1 = evalExpr t1
              v2 = evalExpr t2

solve expr = do
    let expr' = takeWhile (\c->c/='=') expr
    let tkn = tokens expr'
    let tree = parseExpr tkn Empty
    let val = evalExpr tree
    print val

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