Suppose we want to calculate A = XYZ

Matrix multiplication is associative, so the above statement is unambiguous. We can either calculate

A = (XY)Z

or

A = X(YZ)

There is a related optimisation problem known as Matrix chain multiplication, which asks which order is the most efficient.