I am trying to understand this example of converting PDA to CFG but I am not getting the idea quite right. I do have the general understanding of theorem that if $p,q\ \epsilon\ Q $ and $X \varepsilon\ \Gamma$ for $[pXq]$ we have include the sequence of derivations which would pop X from the stack.
I partially understand what is going on but I cannot seem to understand how do I unroll the productions to form strings so I can understand it clearly. Take the production (5) in the example for instance. From what I understand it we are in state p we want to pop A and in the end we should be in state p with empty stack. As we are reading 0 we have zero in the production followed by $[pAq][qAp]$, this is the thing which I am not understanding because if we look at the PDA there is no way of going to q on reading 0. I would like to know what really is going on.
A related question is answered here but I cannot understand it how to clear my confusion.