13.397 Two trains depart simultaneously from A and B towards each other and meet at a distance of $p$ km from B. After $t$ hours from the meeting, the second train, having passed point A, was $q$ km away from it, while the first train, having passed point B, was at a distance from the second train that was twice the distance between A and B. Find the speeds of the trains and the distance between A and B.
Solution. Let $x$ and $y$ be the speeds of the trains, and $z$ be the distance between A and B. Then $\frac{z}{x+y}=\frac{p}{y}$ is the time the trains travel until their first meeting;

$t y=q+(z-p)-$ is the distance traveled by the second train after the meeting, $t(x+y)-$ is the total distance traveled by both trains after the meeting. In the end, we have:
\[
\left\{
\begin{array}{l}
\frac{z}{x+y}=\frac{p}{y}, \\
t(x+y)=2 z, \\
t y=q+z-p .
\end{array}
\right.
\]

Multiplying the first two equations, we get:

$z=3 p-q, x=\frac{4 p-2 q}{t}$.

Answer: $\frac{4 p-2 q}{t}$ km/h; $\frac{2 p}{t} \text{km} / \mathbf{h} ; 3 p-q$ km.