5. For sets $A$ and $B$, their union $A \cup B=\left\{a_{1}, a_{2}\right.$, $\left.\cdots, a_{n}\right\}$, when $A \neq B$, $(A, B)$ and $(B, A)$ are considered different pairs. Then the number of such pairs $(A, B)$ is $\qquad$
$5.3^{n}$.
First consider $A, A$ has $k$ elements $(k=0,1,2, \cdots, n)$, there are $C_{i}^{k}$ $A$s. For each $A$, since $(A \cup B) \backslash A \subset B$, $B$ has $2^{k}$ possibilities for each element in $A$ to exist or not. Thus, according to the problem, the number of pairs $(A, B)$ that satisfy the requirement is
$$
\mathrm{C}_{n}^{n} \cdot 2^{n}+\mathrm{C}_{n}^{n-1} \cdot 2^{n-1}+\cdots+\mathrm{C}_{n}^{1} \cdot 2+\mathrm{C}_{n}^{0} \cdot 2^{0}=3^{n} .
$$