Don’t repeat posts from children in parent taxonomy query

If your post have always children and parent category you can just skip the query for parent using continue:

foreach( $terms as $term ) :
  echo '<h3>'. $term->name. '</h3>'; 
  if ( $term->parent == 0 ) continue;
  // rest of your code here

Problem whith this is only that if a post has a parent term, but doesn’t have any children term you’ll never see that post.