(0) Obligation:

Q restricted rewrite system:
The TRS R consists of the following rules:

f(f(x)) → f(g(f(x), x))
f(f(x)) → f(h(f(x), f(x)))
g(x, y) → y
h(x, x) → g(x, 0)

Q is empty.