For both loops move
<a href="https://wordpress.stackexchange.com/questions/67673/<?php the_permalink(); ?>">
To after
while ( $the_query->have_posts() ) : $the_query->the_post();
the_permalink()
is template tag and as such generates what it does, based on global $post
variable. In your custom loop it doesn’t contain the post you want until after $the_query->the_post()
call.