8. (1987 American Invitational Mathematics Examination) For a given sequence of distinct real numbers $r_{1}, r_{2}, r_{3}, \cdots, r_{n}$, an operation consists of comparing the second term with the first term, and swapping them if and only if the second term is smaller; this process continues until the last term is compared with its new predecessor, and they are swapped if and only if the last term is smaller. For example, the following diagram shows how the sequence $1, 9, 8, 7$ is transformed into the sequence $1, 8, 7, 9$ through one operation. The two numbers being compared at each step are marked with a “-” below them.
$$
\begin{array}{cccc}
\underline{1} & 9 & 8 & 7 \\
1 & \underline{9} & 8 & 7 \\
1 & 8 & \underline{9} & 7 \\
1 & 8 & \underline{7} & 9 \\
\hline
\end{array}
$$

Clearly, any given sequence can be transformed into a non-decreasing sequence through one or more such operations. Now assume $n=40$, and $r_{1}, r_{2}, \cdots, r_{40}$ are distinct and randomly arranged. Let $\frac{p}{q}$ (in lowest terms) be the probability that the 20th term $\left(r_{20}\right)$ is moved to the 30th position through one operation. Find the value of $p+q$.
8. We note the following fact: After applying the operation defined in the problem to any sequence $r_{1}, r_{2}, \cdots, r_{k}$ once, the last number must be the largest number in the sequence.
Therefore, in the initial sequence $r_{1}, r_{2}, \cdots, r_{20}, \cdots, r_{30}, r_{31}, \cdots, r_{40}$, for $r_{20}$ to move to the 30th position through one operation, the necessary and sufficient condition is:
In the first 31 numbers $r_{1}, r_{2}, \cdots, r_{30}, r_{31}$, $r_{31}$ is the largest number, and $r_{20}$ is the second largest number just below $r_{31}$.
Thus, the required probability is: $\frac{p}{q}=\frac{29!}{31!}=\frac{1}{31 \times 30}=\frac{1}{930}$.
Therefore, $p+q=931$.