8.6 Each student in the eighth grade is friends with exactly two students in the seventh grade, and each student in the seventh grade is friends with exactly three students in the eighth grade. There are no more than 29 students in the eighth grade, and no fewer than 17 in the seventh grade. How many students are there in the eighth grade? And in the seventh grade? Provide all possible answers and prove that there are no others.
Solution. Let there be $s$ students in the 8th grade and $-t$ in the 7th grade. Then the number of pairs of friends from different grades is $2s$ and it is also equal to $3t$. From the equality $2s = 3t$, we see that $s$ is a multiple of 3, and $t$ is a multiple of 2. Therefore, $2s = 3t$ is a multiple of 6. Additionally, $2s \leq 58$, $3t \geq 51$. Hence, $2s = 3t = 54$, $s = 27$, $t = 18$.

Answer: There are 27 students in the 8th grade and 18 in the 7th grade.

Note. The problem does not require constructing an example of a friendship system that satisfies the condition of the problem. It is assumed a priori that the situation described in the condition is possible.

| INCLUDED IN THE SOLUTION | SCORE |
| :---: | :---: |
| Correct and justified answer | 7 points |
| Three statements are proven:  - there are one and a half times more 8th graders than 7th graders  - the number of 8th graders is a multiple of $3$;  - the number of 7th graders is even | 6 points |
| Two out of three statements (see 6 points item) are proven | 4 points; |
| One out of three statements (see 6 points item) is proven | 2 points |
| Correct answer without justification or a correct example of such classes and a system of friendships among students | 1 point |