Apply the chain rule through a three-layer scalar network to compute intermediate activations and parameter gradients.