8. In a unit square, if two of its four sides are colored with color $i$, and the other two sides are colored with two different colors other than $i$, then the unit square is called “$i$-dominated”. As shown in the figure, a $1 \times 3$ grid consists of 10 unit line segments. Now, we need to color these 10 line segments, each with one of the three colors: red, yellow, or blue, such that there is one red-dominated, one yellow-dominated, and one blue-dominated unit square. The number of such coloring ways is $\qquad$ (answer in numerical form).
As shown in the figure, let the three unit squares from left to right in the $1 \times 3$ grid be dominated by colors 1, 2, and 3, respectively. Then, among the four line segments $a, b, c, d$, two are colored with color 2, and the other two are colored with colors 1 and 3. There are 12 ways to color them. If $a, b$ are colored with color 2, and $c, d$ are colored with colors 1 and 3, respectively, then the left three line segments are colored as $1,1,3$, and the right three line segments are colored as $1,2,3$. In this case, there are $3 \times 6=18$ ways to color them; if $a, b$ are colored with color 2, and $c, d$ are colored with colors 3 and 1, respectively, then the left three line segments are colored as $1,1,3$, and the right three line segments are colored as $2,3,3$. In this case, there are $3 \times 3=9$ ways to color them; if $a, c$ are colored with color 2, and $b, d$ are colored with colors 1 and 3, respectively, then the left three line segments are colored as $1,2,3$, and the right three line segments are colored as $1,2,3$. In this case, there are $6 \times 6=36$ ways to color them; if $a, c$ are colored with color 2, and $b, d$ are colored with colors 3 and 1, respectively, then the left three line segments are colored as $1,1,2$, and the right three line segments are colored as $2,3,3$. In this case, there are $3 \times 3=9$ ways to color them; if $a, d$ are colored with color 2, and $b, c$ are colored with colors 1 and 3, respectively, then the left three line segments are colored as $1,2,3$, and the right three line segments are colored as $1,3,3$. In this case, there are $6 \times 3=18$ ways to color them; if $a, d$ are colored with color 2, and $b, c$ are colored with colors 3 and 1, respectively, then the left three line segments are colored as $1,1,2$, and the right three line segments are colored as $1,3,3$. In this case, there are $3 \times 3=9$ ways to color them; if $b, c$ are colored with color 2, and $a, d$ are colored with colors 1 and 3, respectively, then the left three line segments are colored as $1,1,3$, and the right three line segments are colored as $1,2,3$. In this case, there are $3 \times 6=18$ ways to color them; if $b, c$ are colored with color 2, and $a, d$ are colored with colors 3 and 1, respectively, then the left three line segments are colored as $1,1,3$, and the right three line segments are colored as $2,3,3$. In this case, there are $3 \times 3=9$ ways to color them; if $b, d$ are colored with color 2, and $a, d$ are colored with colors 1 and 3, respectively, then the left three line segments are colored as $1,1,3$, and the right three line segments are colored as $1,3,3$. In this case, there are $3 \times 3=9$ ways to color them; if $b, d$ are colored with color 2, and $a, d$ are colored with colors 3 and 1, respectively, then the left three line segments are colored as $1,1,3$, and the right three line segments are colored as $1,3,3$. In this case, there are $3 \times 3=9$ ways to color them; if $c, d$ are colored with color 2, and $a, d$ are colored with colors 1 and 3, respectively, then the left three line segments are colored as $1,1,2$, and the right three line segments are colored as $1,3,3$. In this case, there are $3 \times 3=9$ ways to color them; if $c, d$ are colored with color 2, and $a, d$ are colored with colors 3 and 1, respectively, then the left three line segments are colored as $1,2,3$, and the right three line segments are colored as $1,3,3$. In this case, there are $6 \times 3=18$ ways to color them.
In summary, there are $18 \times 4 + 9 \times 7 + 36 = 171$ ways to color them. Considering the cyclic nature of the three colors, the number of coloring methods that meet the conditions is $171 \times 6 = 1026$.