# Simplifying trace of matrix product — why does this hold?

I have a question about a line in the textbook "Gaussian Processes for Machine Learning" by Rasmussen and Williams (available here). On page 125 (equation 5.23), they write the following:

$$-\frac{1}{2} tr(B^{-1}K\frac{\partial W}{\partial \hat{f_i}}) = -\frac{1}{2}[(K^{-1} + W)^{-1}]_{ii}\frac{\partial^{3}}{\partial f_i^{3}} \textrm{log} p(y|\hat{f})$$.

where:

$$W = -\nabla \nabla \textrm{log} p(y | \hat{f})$$ (which is diagonal in this case, with all-positive entries).

$$B = I + W^{\frac{1}{2}}KW^{\frac{1}{2}}$$

$$K$$ is symmetric and positive definite.

By using the trace and the fact that the only element of $$\frac{\partial W}{\partial \hat{f_i}}$$ that is going to be non-zero is the $$ii$$ element, I think I managed to arrive at:

$$-\frac{1}{2} tr(B^{-1}K\frac{\partial W}{\partial \hat{f_i}}) = -\frac{1}{2}(B^{-1}K)_{ii}(\frac{\partial W}{\partial \hat{f_i}})_{ii}$$

But I don't understand how to get from $$(B^{-1}K)_{ii}$$ to $$[(K^{-1} + W)^{-1}]_{ii}$$, and I am not convinced I am on the right track. Any help would be appreciated!