It's not magic. You have to look at it and encourage it to make sense.

The numerator is a little funny, so switch it around so that it looks like you expect:

12-x-x^2 = -x^2 - x + 12 = -(x^2 + x - 12)

That's better. Now it is easy to see that we need 4*(-3) = 12 and 4 + (-3) = +1

The denominator should be an eyeball problem.

(-1)*(-3) = +3 and (-1)+(-3) = -4