We observe
x2+3x+2=(x+1)(x+2) and x2+7x+12=(x+3)(x+4).
Thus
p(x)=(x+1)(x+2)(x2+2x+a), q(x)=(x+3)(x+4)(x2+7x+b)
Hence x+3 divides x2+2x+a and x+1 divides x2+7x+b. Write
x2+2x+a=(x+3)f(x), x2+7x+b=(x+1)(g(x), for some polynomials f(x) and g(x). Taking x=−3 in the first relation above, we get (−3)2+2×(−3)+a=0. We get a=−3. Taking x=−1 in the second relation, we get (−1)2+7×(−1)+b=0. We get b=6.