the decryptNode function for leaf nodes in CP-ABE

Can someone please explain to me why decryptNode gives as result $$e(g,g)^rq(0)$$ for leaf nodes, I don't understand how they went from the second step to the third (here is the article: Ciphertext-Policy Attribute-Based Encryption), also note that there is an error in the second step, it's $$g^q(0)$$ and not $$h^q(0)$$

Since $H$ is a hash that projects into $\mathbb{G}_0$, one must be able to write $H(i)$ as $g^z$ for some unknown $z$, because $g$ is a generator of $\mathbb{G}_0$.
The last step works because $e(g, g)^a\cdot e(g, g)^{-a} = 1$.