Adding css tweak based on page template

In your wp_query loop you’ll want to check the page template of the current post object. You’ll be able to set that to a string and use it however you want

Close to this:

while ( $query->have_posts() ) : $query->the_post(); 
if (is_page) {
  $pageTemplate = basename( get_page_template() );
  echo "<p class=\"" . $pageTemplate . "\">" . get_the_title() . "</p>";
}
endwhile;

Refer to the codex page for more info on the function