In the second case, three grids are fixed and three colors are randomly selected, so there are A33 methods. The color of the other grid is fixed, but it is divided into BC as a group and AD as a group, so it is 3*2*2= 12.
So the answer is 18 method, (you counted it wrong above)