The problem is difficult to express with the Leibniz-style notation for partial derivatives: ##\frac d{dx}, \frac\partial{\partial x}##. So let's switch notation to one that specifically indicates the number of which argument we are differentiating against. The operator ##D{}_k## denotes
partial differentiation of a function wrt its ##k##-th argument. Where there is only one argument we can drop the subscript and just write ##D{}##. That notation makes writing the problem easier.
First let's rewrite the first problem:
We have functions ##f:\mathbb R^2\to\mathbb R## and ##g:\mathbb R\to\mathbb R##.
The first equation in the OP can be written as:
$$\forall a:\ \ (D{}_1 f) (g(a),a)= 0$$
and the second equation is:
$$\forall a:\ \ (D{} h)(a) = 0$$
where ##h:\mathbb R\to \mathbb R## is defined as ##h(x)=(D{}_1 f)(g(x),x)##, that is, the function ##(D{}_1 f):\mathbb R^2\to\mathbb R## applied to the arguments ##g(x)## and ##x##.
We can rewrite that last equation by applying the total derivative rule, as:
$$0 = (D{} h)(a)
= (D{}_1 (D{}_1 f))(g(a),a)\cdot (D{} g)(a)
+(D{}_2(D{}_1 f))(g(a),a)
$$
whence we deduce the wanted result:
$$(D{} g)(a)
= - \frac{(D{}_2D{}_1 f)(g(a),a)}
{(D{}_1 D{}_1 f)(g(a),a)}
$$
Now let's apply the same procedure to the extended case, using functions ##f:\mathbb R^3\to\mathbb R## and ##g:\mathbb R^2\to\mathbb R##.
First equation is:
$$\forall a,b:\ \ (D{}_1 f) (g(a,b),a,b)= 0$$
The second equation is a pair:
$$\forall a:\ \ (D{} h_a)(a) = 0$$
$$\forall b:\ \ (D{} h_b)(b) = 0$$
where functions ##h_a,h_b:\mathbb R\to\mathbb R## are defined by:
$$h_a(x) = (D{}_1 f)(g(x,b),x,b)$$
that is, the function ##(D{}_1 f):\mathbb R^3\to\mathbb R## applied to the arguments ##g(x,b)##, ##x## and ##b##;
and
$$h_b(x) = (D{}_1 f)(g(a,x),a,x)$$
that is, the function ##(D{}_1 f):\mathbb R^3\to\mathbb R## applied to the arguments ##g(a,x)##, ##a## and ##x##.
We expand the pair of equations using the total derivative rule, to get:
$$0 = (D{} h_a)(x)
= (D{}_1 (D{}_1 f))(g(x,b),x,b)\cdot (D{}_1 g)(x,b)
+(D{}_2(D{}_1 f))(g(x,b),x,b)
$$
and
$$0 = (D{} h_b)(x)
= (D{}_1 (D{}_1 f))(g(a,x),a,x)\cdot (D{}_2 g)(a,x)
+(D{}_3(D{}_1 f))(g(a,x),a,x)
$$
whence we deduce the wanted results:
$$(D{}_1 g)(a,b)
= - \frac{(D{}_2D{}_1 f)(g(a,b),a,b)}
{(D{}_1 D{}_1 f)(g(a,b),a,b)}
$$
and
$$(D{}_2 g)(a,b)
= - \frac{(D{}_3D{}_1 f)(g(a,b),a,b)}
{ (D{}_1 D{}_1 f)(g(a,b),a,b)}
$$
noting that we have replaced ##x## by ##a## in the first equation and ##b## in the second.
The insights article
here explains the confusion that is frequently created by the Leibniz notation for partial derivatives, and proposes the system used in this post as a means of clearing up the confusion.