Let p(x)=x(ax+b)=ax2+bx (a second degree polynomial degree which is divisible by x).
Using synthetic division on x-1 and x+2:
1 | a b 0
a a | a+b
a a+b | -2, so a+b=-2, a=-2-b;
-2 | a b 0
a -2a | -2b+4a
a b-2a | 10, so -2b+4a=10, -2b-8-4b=10, -6b=18, b=-3⇒a=1.
p(x)=x2-3x is the polynomial.
CHECK
(x2-3x)/(x-1)=x-2-2/(x-1)=(x2-3x+2-2)/(x-1)=(x2-3x)/(x-1)✔️;
(x2-3x)/(x+2)=x-5+10/(x+2)=(x2-3x-10+10)/(x+2)=(x2-3x)/(x+2)✔️.