Find the total number of ways a 3×n board can be painted using 3 colors while making

sure no cells of the same row or the same column have entirely the same color. The

answer must be computed modulo 10^9+7.

It’s answer is 24^n−9×8^n+18×3^n+9×2^n−24, but how?

answer for n=1,2,3,4 respectively are 0, 174, 9750, 296490,…