5. Suppose there are 10 red, 10 yellow, and 10 blue small balls. Now, all of them are to be placed into two bags, A and B, such that each bag contains balls of two colors, and the sum of the squares of the number of balls of two colors in bags A and B are equal. There are $\qquad$ ways to do this.
5.61.

Let the number of red, yellow, and blue balls in bag A be $x, y, z (1 \leqslant x, y, z \leqslant 9)$. Then the number of balls of corresponding colors in bag B are $10-x, 10-y, 10-z$.
First, assume $x \leqslant y \leqslant z$.
From the problem, we know
$$
\begin{array}{l} 
x^{2}+y^{2}+z^{2}=(10-x)^{2}+(10-y)^{2}+(10-z)^{2} \\
\Rightarrow x+y+z=15 \\
\Rightarrow(x, y, z) \\
=(1,5,9),(1,6,8),(1,7,7), \\
(2,4,9),(2,5,8),(2,6,7), \\
(3,3,9),(3,4,8),(3,5,7), \\
(3,6,6),(4,4,7),(4,5,6), \\
(5,5,5) .
\end{array}
$$

Considering other possible orders of $x, y, z$, we find there are
$$
8 \times 3 \times 2 \times 1+4 \times 3+1=61
$$

ways to place the balls.