8. In a unit square, if three of its four sides are colored with three different colors, then the unit square is called "colorful". As shown in the figure, a $1 \times 3$ grid table contains 10 unit line segments in its grid lines. Now, we need to color these 10 line segments, with each line segment being colored red, yellow, or blue, such that all three unit squares are colorful. The number of such coloring ways is $\qquad$ (answer in numerical form).
As shown in the figure, the coloring methods for $a, b, c, d$ are $C_{4}^{2} \cdot A_{3}^{3}=36$. At this point, the coloring methods for the three line segments of the left unit square are $C_{3}^{1} \cdot A_{2}^{2} + C_{3}^{2} \cdot C_{2}^{1}=12$ kinds. Similarly, the coloring methods for the three line segments of the right unit square are also 12 kinds. Therefore, the total number of coloring methods that meet the conditions is $36 \cdot 12^{2}=5184$.