Given $g(x)$ and $f(g(x))$, solve for $f(x)$.

I've hit a wall on the above question and was unable to find any online examples that also contain trig in $f(g(x))$. I'm sure I am missing something blatantly obvious but I can't quite get it.

$$g(x)=3x+4 , \quad f(g(x)) = \cos\left(x^2\right)$$

So far I've managed to get to the point where I have $f(x+8) = \cos\left(x^2\right)$, by solving $g^{-1}(g(x))$ (loosely based on the last bit of advice here), but I can't make that final connection.

My best attempt so far was $f(x)=\cos(x^2-16x+64)$, but while that does result in $x^2$, it still ends up wrong due to it being cosine.

-

Hint: $(f \circ g) \circ g^{-1} =f \circ (g \circ g^{-1}) = f$
$$y=g(x)=3x+4$$ $$x=\frac{y-4}{3} \Rightarrow g^{-1}(x)=\frac{x-4}{3}$$ $$f=f \circ (g \circ g^{-1})=(f \circ g) \circ g^{-1} =\cos \left(\frac{x-4}{3} \right)^2$$