4. A bag contains $m$ red balls and $n$ white balls, $m>n \geqslant 4$. Now, two balls are drawn at random. If the probability of drawing two balls of the same color is equal to the probability of drawing two balls of different colors, then the number of arrays $(m, n)$ that satisfy the relation $m+n \leqslant 40$ is $\qquad$
Let $A=$ "the two balls drawn are of the same color", $B=$ "the two balls drawn are of different colors", then $P(A)=\frac{C_{m}^{2}+C_{n}^{2}}{C_{m+n}^{2}}, P(B)=\frac{C_{m}^{1} \cdot C_{n}^{1}}{C_{m+n}^{2}} \Rightarrow \frac{m(m-1)}{2}+\frac{n(n-1)}{2}=m n$ $\Rightarrow m^{2}+n^{2}-2 m n=m+n \Rightarrow(m-n)^{2}=m+n \Rightarrow m+n=16,25,36$. Therefore, $(m, n)=(10,6),(15,10),(21,15)$, a total of 3 pairs.