Let's first determine how many students participated in the race. If there are 39 students in total and all but 8 participated, then:
Number of students who participated = Total students - Students who did not participate
= 39 - 8
= 31
Now, each participating student paid $6. To find the total cost, we multiply the number of participants by the cost per participant:
Total cost = Number of participants × Cost per participant
= 31 × $6
= $186
So, the total cost is $186.