1. The sides of a square $A B C D$ with a side length of 10 are reflective on the inside. A light ray enters the square through the vertex $A$ and travels to the point $P$ on $C D$ with $C P=3$ and $P D=7$. At $P$, it naturally reflects off the side $C D$. The light ray can only leave the square through one of the vertices $A, B, C$ or $D$.

What is the distance that the light ray travels inside the square before it leaves the square?

Through which vertex does this happen?
1. For convenience, let's assume the length of the side is 1. Instead of constructing the reflection of the line $A P$ in point $P$ within the square, you can also reflect the square in the side $C D$ and then extend the line $A P$ into the reflected square. You can keep repeating this procedure until the line passes through a vertex of one of the many reflected squares. If we introduce coordinates: $A(0,0), B(1,0), C(1,1)$, and $D(0,1)$, then the light ray will exit a square through the grid point $(7,10)$. The light ray will have traveled a total distance of $\sqrt{7^{2}+10^{2}}=\sqrt{149}$. It is easy to verify that the letter at that vertex is $B$ because all grid points with an $A$ have even coordinates, all grid points with a $C$ have odd coordinates, and all grid points with a $B$ have an odd $x$-coordinate and an even $y$-coordinate. Since it is given that the side of the square is 10, the total distance is $10 \sqrt{149}$.