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

parse :: String -> (Int, String)
parse xs =
    let (prev,t:rst) = break (== ']') xs
        x = read prev
    in ((x + 1) `div` 2, rst)

calc :: [Int] -> Int
calc xs =
    let m = ((length xs) + 1) `div` 2
    in sum $ take m $ sort xs

solve :: [Int] -> String -> (Int, String)
solve stk "" = (calc stk, "")
solve stk (c:cs)
    | c == '['  =
        let (x, rst) = solve [] cs
        in solve (x:stk) rst
    | c == ']'  =
        let x = calc stk
        in (x, cs)
    | otherwise = parse (c:cs)

main :: IO ()
main = do
    n <- readLn
    ls <- replicateM n getLine :: IO [String]
    mapM_ print $ map (fst . solve []) ls