4. $A=\left\{a_{1}, a_{2}, a_{3}, a_{4}\right\}, B=\left\{a_{1}^{2}, a_{2}^{2}, a_{3}^{2}, a_{4}^{2}\right\}$. Here, $a_{1}<a_{2}<a_{3}<a_{4}, a_{1}, a_{2}, a_{3}, a_{4} \in \mathbf{N}^{\top}$. If $A \cap B=\left\{a_{1}, a_{4}\right\}, a_{1}+a_{4}=10$, and the sum of all elements in $A \cup B$ is 124. Find the sets $A$ and $B$.
4. Solving easily, we get $a_{1}=1, a_{4}=9$, divided into two cases for discussion: $a_{2}^{2}=9$ and $a_{3}^{2}=9$, we can get: $a_{1}=1, a_{2}=3, a_{3}$ $=4, a_{4}=9$.