I'm reading the paper "Isolating Sources of Disentanglement in VAEs". Assuming $p(n)$ is a uniform distribution and that we have a model to get $q(z|n)$ for any input $n$. Also, $q(z|n)$ represents a normal distribution, so the model predicts the mean and covariance matrix for $q(z|n)$. Please consider the following minibatch-based estimation provided by the author.

Question 1. I don’t understand how the third line follows from the second line, where $E_{p(B_M)}$ is introduced along with averaging over the values of $q(z|n_m)$. It is somewhat intuitive, but I'd like to know concretely.

Question 2. What happened to $E_r(B_M|n)$ in (S4)?