How to setup a query to output posts by groups of five?

you can create a simple counter and condition:

 <?php $count = 0; ?>
    <?php if( $query->have_posts() ) : ?>
        <ul class="posts">
            <?php while ( $query->have_posts() ) : $query->the_post();
            if ($count < 5){ 
                ?>
                <li>
                    <?php the_title(); ?>
                </li> 
                <?php
            }else{
                echo '</ul><ul class="posts">';         
            ?>
                <li>
                    <?php the_title(); ?>
                </li> 
                <?php
                $count = 0;
            }
            $count = $count + 1;
            <?php endwhile; ?>
        </ul>
    <?php endif; ?>