7. 12 For a known sequence of distinct real numbers $r_{1}, r_{2}, r_{3}, \cdots$, $r_{n}$, one 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 preceding term, and they are swapped if and only if the last term is smaller. For example, the table below 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 "——" below them.
\begin{tabular}{llll}
1 & 9 & 8 & 7 \\
1 & 9 & 8 & 7 \\
1 & 8 & 9 & 7 \\
1 & 8 & 7 & 9
\end{tabular}

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 ($r_{20}$) is moved to the 30th position through one operation. Find the value of $p+q$.
[Solution] We note the following fact:
For any sequence
$$r_{1}, r_{2}, \cdots, r_{k}$$

after performing the operation defined in the problem once, the last number must be the largest number in the sequence.
Therefore, in an 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 \text { ! }}{31!}=\frac{1}{31 \times 30}=\frac{1}{930}$.
Therefore, $p+q=931$.