In a classroom, there are 25 students. The teacher wants to divide them into groups based on their preferences for different subjects. Each student must choose exactly one subject from the following: Math, Science, or History.
If the number of students who chose Math is three times the number of students who chose History, and if the total number of Science students is 5 more than the number of History students, how many students chose each subject?