That (x−3) is the HCF, means (x−3) is a factor of both the polynomials. Hence p(x)=(x−3)f(x) and q(x)=(x−3)g(x) for some polynomials f(x) and g(x).
by taking x=3. we see that p(3)=0 and q(3)=0. thus
0=p(3)=33+a×32+b×3−6=21+9a+3b
0=q(3)=33−3(b−4)+a=39−3b+a.
We get two simultaneous linear equations for a and b;
9a+3b=−21
a−3b=−39
Adding these tow we get 10a=−60 or a=−6. From the second equation 3b=a+39=−6+39=33. hence b=11.