How to prove $g(d,\ f(g(d,\ d),\ d,\ d))$ as a correct term in Predicate Logic

I have been learning Predicate Logic recently and I get a following question:

Assumed $ \ F = \{m,\ f\}, P = \{S,\ B\}$ , in which $ m$ is constant, $ f$ is ternary function, $ g$ is binary function, prove $ g(d,\ f(g(d,\ d),\ d,\ d))$ as a correct Term in Predicate Logic.

I want to prove it by drawing a parse tree or inductive reasoning, but I don’t know the which one is mathematical rigor.

If not mind, could anyone tell me the mathematical rigor way to prove the correctness of Term and Formula in Predicate Logic and prove it?

Thanks in advance.