-- ?????????
-- http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0109

import Control.Monad

data Tree a = Leaf a | Branch Char (Tree a) (Tree a) deriving Show

mylex :: String -> [String]
mylex xs = case head (lex xs) of
    ([] , []) -> []
    (x , y) -> x : mylex y

parse_factor :: [String] -> (Tree Int , [String])
parse_factor ("(":xs) = case parse_expr xs of
    (t , ")" : rest) -> (t , rest)
    (_ , _) -> error "'(' is not closed."
parse_factor ("-":x:xs) = (Leaf $ negate $ read x , xs) -- number ?
parse_factor (x:xs) = (Leaf $ read x , xs) -- number ?
parse_factor [] = error "The empty string is not an expression."

parse_term :: [String] -> (Tree Int , [String])
parse_term xs = case parse_factor xs of
    (t , rest) -> parse_term' t rest

parse_term' :: Tree Int -> [String] -> (Tree Int , [String])
parse_term' t ("*":xs) = let rest' = parse_factor xs in parse_term' (Branch '*' t (fst rest')) (snd rest')
parse_term' t ("/":xs) = let rest' = parse_factor xs in parse_term' (Branch '/' t (fst rest')) (snd rest')
parse_term' t xs = (t , xs)

parse_expr :: [String] -> (Tree Int , [String])
parse_expr xs = case parse_term xs of
    (t , rest) -> parse_expr' t rest

parse_expr' :: Tree Int -> [String] -> (Tree Int , [String])
parse_expr' t ("+":xs) = let rest' = parse_term xs in parse_expr' (Branch '+' t (fst rest')) (snd rest')
parse_expr' t ("-":xs) = let rest' = parse_term xs in parse_expr' (Branch '-' t (fst rest')) (snd rest')
parse_expr' t xs = (t , xs)

parse :: [String] -> Tree Int
parse xs = case parse_expr xs of
    (t , ["="]) -> t
    (_ , []) -> error $ "The end of expression must be '='"
    (_ , ys) -> error $ "failed to parse. " ++ show ys

calc :: Tree Int -> Int
calc (Leaf x) = x
calc (Branch '+' x y) = calc x + calc y
calc (Branch '-' x y) = calc x - calc y
calc (Branch '*' x y) = calc x * calc y
calc (Branch '/' x y) = calc x `quot` calc y
calc (Branch op _ _) = error $ "unknown operator '" ++ [op] ++ "'."

solve :: String -> IO ()
solve s = -- print t >> 
    print (calc t)
    where t = parse $ mylex s

main :: IO ()
main = readLn
    >>= (\ n -> replicateM n getLine)
    >>= mapM_ solve