4. Given that $m, n$ are positive integers, $A_{1}, A_{2}, \cdots, A_{m}$ are all sets containing $n$ positive integer elements, and these sets are pairwise disjoint. Additionally, any element in $A_{i}$ cannot be divisible by any element in $A_{i+1}$ (the index $i$ is taken modulo $m$), where $i=1,2, \cdots, m$. Find the maximum number of ordered pairs $(a, b)$, where $a, b$ are elements from different sets $A_{i}$, and $a \mid b$.
4. The maximum value sought is $n^{2} \mathrm{C}_{m-1}^{2}$, and an example achieving this maximum value is
$$
\begin{array}{l}
A_{k}=\left\{p^{(k-1) n+1}, p^{(k-1) n+2}, \cdots, p^{k n}\right\}(k=1, \cdots, m-1), \\
A_{m}=\left\{q, q^{2}, \cdots, q^{n}\right\},
\end{array}
$$

where $p$ and $q$ are both prime numbers.
For convenience, an ordered pair $(a, b)$ that satisfies the conditions is called "appropriate".

Next, we prove that the number of appropriate ordered pairs does not exceed $n^{2} \mathrm{C}_{m-1}^{2}$.

For each $m$-tuple $\left(a_{1}, a_{2}, \cdots, a_{m}\right)$, where $a_{k}(k=1,2, \cdots, m)$ is an element of $A_{k}$.

Let $k\left(a_{1}, a_{2}, \cdots, a_{m}\right)$ denote the number of appropriate ordered pairs $\left(a_{i}, a_{j}\right)$ in the tuple $\left(a_{1}, a_{2}, \cdots, a_{m}\right)$.
We will prove by induction on $m$ that
$$
k\left(a_{1}, a_{2}, \cdots, a_{m}\right) \leqslant \mathrm{C}_{m-1}^{2} \text {, }
$$

Since there are exactly $n^{m}$ $m$-tuples, and each appropriate ordered pair is included in exactly $n^{m-2}$ $m$-tuples, the number of appropriate ordered pairs does not exceed $n^{2} \mathrm{C}_{m-1}^{2}$.
The case $m=3$ is clearly true.
For $m \geqslant 4$, fix an $m$-tuple $\left(a_{1}, a_{2}, \cdots, a_{m}\right)$, where $a_{k} \in A_{k}(k=1,2, \cdots, m)$. Without loss of generality, assume $a_{1}$ is the largest element in the tuple. The $(m-1)$-tuple $\left(a_{2}, a_{3}, \cdots, a_{m}\right)$ satisfies the conditions:
$$
a_{2} \nmid a_{1}, a_{3} \nmid a_{2}, \cdots, a_{m-1} \nmid a_{m-2} \text {, }
$$

and since $a_{1}$ is the largest, we have $a_{1} \nmid a_{m-1}$.
Finally, we prove that the number of appropriate ordered pairs containing $a_{m}$ does not exceed $m-2$.
In this case,
$$
\begin{array}{l}
k\left(a_{1}, a_{2}, \cdots, a_{m}\right) \\
\leqslant k\left(a_{1}, a_{2}, \cdots, a_{m-1}\right)+m-2 \\
\leqslant \mathrm{C}_{m-2}^{2}+m-2 \\
=\mathrm{C}_{m-1}^{2} .
\end{array}
$$

Note that, as $k$ ranges from 1 to $m-1$, at most one of $\left(a_{k}, a_{m}\right)$ and $\left(a_{m}, a_{k}\right)$ is appropriate.

If for some $k$, neither $\left(a_{k}, a_{m}\right)$ nor $\left(a_{m}, a_{k}\right)$ is appropriate, then the number of appropriate ordered pairs containing $a_{m}$ does not exceed $m-2$. Otherwise, since the pairs $\left(a_{m}, a_{k}\right)$ and $\left(a_{k+1}, a_{m}\right)(k=1,2, \cdots, m-2)$ cannot both be appropriate, and the pair $\left(a_{1}, a_{m}\right)$ is clearly not appropriate.

Therefore, if all pairs $\left(a_{m}, a_{k}\right)(k=1,2, \cdots, m-1)$ are appropriate, this contradicts $a_{m} \nmid a_{m-1}$.