Since $\pi$ sends pairs $(m, n)$ with $m+n$ prime to pairs $\left(m^{\prime}, n^{\prime}\right)$ with $m^{\prime}+n^{\prime}$ prime, and there are only finitely many such pairs, we conclude that if $m+n$ is composite, then so is $\pi(m)+\pi(n)$. Also note that $2 \pi(1)=\pi(1)+\pi(1)$ is prime because $2=1+1$ is prime. Thus, $\pi(1)=1$. Now, since $1+2,1+4,1+6$, and $1+10$ are all prime, we know that $\pi(2), \pi(4), \pi(6)$, and $\pi(10)$ are all even. Additionally, since $8+2,8+6,8+6$, and $8+10$ are all composite, it is not hard to see that $\pi(8)$ must also be even. Therefore $\pi$ preserves parity. Now, draw a bipartite graph between the odd and even numbers where we have an edge between $a$ and $b$ if and only if $a+b$ composite. We now only need to compute automorphisms of this graph that fix 1. Note that the edges are precisely $1-8-7-2,3-6-9$, and $4-5-10$. Since 1 is a fixed point of $\pi$, we know that $\pi$ fixes $1,8,7$, and 2. Additionally, $\pi(6)=6$ and $\pi(5)=5$. We can swap 3 and 9, as well as 4 and 10. Thus, there are $2 \cdot 2=4$ possible permutations.
Compute the number of permutations $\pi$ of the set $\{1,2, \ldots, 10\}$ so that for all (not necessarily distinct) $m, n \in\{1,2, \ldots, 10\}$ where $m+n$ is prime, $\pi(m)+\pi(n)$ is prime.