<s>[INST] Finding the remainder of a polynomial divided by $x^4+x^2+1$ if remainders when dividing by $x^2+x+1$, $x^2-x+1$ are $-x+1$, $3x+5$. 
Find the remainder of $f$ divided by $g(x)=x^4+x^2+1$ if the remainder of $f$ divided by $h_1 (x)=x^2+x+1$ is $-x+1$ and the remainder of $f$ divided by $h_2(x)=x^2-x+1$ is $3x+5$.

My attempt was to write $f(x)=(x^4+x^2+1)q(x)+Ax^3+Bx^2+Cx+D=(x^2+x+1)(x^2-x+1)q(x)+Ax^3+Bx^2+Cx+D$ and then factor out $x^2+x+1$ to get $f(x)=(x^2+x+1)[(x^2-x+1)q(x)+B]+Ax^3+(C-B)x+(D-B)$, then do the same for $x^2-x+1$ and then use that along with the known remainder of $f$ divided by $x^2+x+1$ and $x^2-x+1$ to obtain $A$, $B$, $C$, $D$. However, $Ax^3$ is in the way so I don't know how to proceed nor do I have any other ideas to start with.
 [/INST] This is where things go wrong:

My attempt was to write $f(x)=(x^4+x^2+1)q(x)+Ax^3+Bx^2+Cx+D=(x^2+x+1)(x^2-x+1)q(x)+Ax^3+Bx^2+Cx+D$ and then factor out $x^2+x+1$ to get $f(x)=(x^2+x+1)[(x^2-x+1)q(x)+B]+Ax^3+(C-B)x+(D-B)$

The remainder inside the brackets can have a linear term as well, so you should have written it as
$$
f(x) = (x^2 + x + 1)[(x^2 - x + 1)q(x) + Ax + (B-A)] + (C-B)x + (D-B+A).
$$
And similarly,
$$
f(x) = (x^2 - x + 1)[(x^2 - x + 1)q(x) + Ax + (B+A)] + (C+B)x + (D-B-A),
$$
at which point you can solve for all four coefficients.
</s>