def f(a)
    if a.size == 1
        a[0] / 2 + 1
    else
        a.map{|b| f(b)}.sort[0..a.size/2].inject(:+)
    end
end
n = gets.to_i
n.times {
    s = gets.chomp.gsub!(/\](?=\[)/, '],')
    p f(eval(s))
}