import Control.Monad
import Control.Applicative hiding ((<|>))
import Text.Parsec
import Text.Parsec.Char

expression = maxmin 
  <$> oneOf "^_" <* char '('
  <*> expression <* char ',' <*> expression <* char ')'
  <|> number
number = makeNumber <$> (sourceColumn <$> getPosition) <*> many1 digit

maxmin c g h a b
  | a' >= b' = (i,z)
  | otherwise = (j,z)
  where 
    (i,x) = g a b
    (j,y) = h a' b'
    (a',b',z) = case c of
      '^' -> (max a x, b, max x y)
      '_' -> (a, min b x, min x y)

makeNumber i s@(c:_) a b
  | x == 0 || x*10+9 <= a || x >= b = (i, read s)
  | otherwise = (i+1, read s)
  where x = read [c]

main = do
  q <- readLn
  replicateM_ q $ do
    s <- getLine
    let (Right f) = parse expression "" s
        (i,x) = f 0 99
    putStrLn $ show x ++ " " ++ show i