Whenever you multiply a matrix on the left with dimension m * n (m rows and n columns) by a matrix on the right with dimension p*q (p rows and q columns), the rule is:
If you write each matrix's dimensions below it, observe the following.. by thinking about what carrying out the matrix multiplication operation means you must do, and seeing that nothing but the following could possibly be true:
a) the inner two dimensions must match. n must equal p
b) the product will have dimensions equal to the outermost dimensions, m * q