def calc(s)
  res = []
  loop do
    if s[$pos] == '['
      $pos += 1
      res << calc(s)
    elsif s[$pos] == ']'
      break
    else  # num
      x = ''
      while s[$pos] != ']'
        x += s[$pos]
        $pos += 1
      end
      return x.to_i / 2 + 1
    end
    $pos += 1
  end
  res.sort.first(res.size/2+1).reduce(:+)
end

gets.to_i.times do
  $pos = 1
  puts calc(gets)
end