# Convert PDA to CFG – Language of Palindromes over $\{a,b\}^+$

I tried to convert the following PDA $$M$$

to a CFG and got the following results. However I’m not quite sure if I did the algorithm the right way. I feel like I maybe misunderstood some the algorithm when it comes to the $$A_{p,q} \to xA_{r,s}y$$ part. Could you help me to clear things up?

$$G = (V,\Sigma,P,S)$$ with \begin{align*} V = \{&A_{0,0},A_{0,1},A_{0,2},A_{0,3},A_{0,4},A_{1,0},A_{1,1},A_{1,2},A_{1,3},A_{1,4},A_{2,0},A_{2,1},A_{2,2},A_{2,3},A_{2,4},\ &A_{3,0},A_{3,1},A_{3,2},A_{3,3},A_{3,4},A_{4,0},A_{4,1},A_{4,2},A_{4,3},A_{4,4},S\}, \end{align*} $$\Sigma = \{a,b\}$$, $$S = A_{0,4}$$ and the following productions: \begin{align*} S &\to A_{0,4}\ A_{0,0} &\to \epsilon\ A_{1,1} &\to \epsilon\ A_{2,2} &\to \epsilon\ A_{3,3} &\to \epsilon\ A_{4,4} &\to \epsilon\ A_{0,0} &\to A_{0,0}A_{0,0} \vert A_{0,1} A_{1,0} \vert A_{0,2}A_{2,0} \vert A_{0,3}A_{3,0} \vert A_{0,4}A_{4,0}\ A_{0,1} &\to A_{0,0}A_{0,1} \vert A_{0,1} A_{1,1} \vert A_{0,2}A_{2,1} \vert A_{0,3}A_{3,1} \vert A_{0,4}A_{4,1}\ A_{0,2} &\to A_{0,0}A_{0,2} \vert A_{0,1} A_{1,2} \vert A_{0,2}A_{2,2} \vert A_{0,3}A_{3,2} \vert A_{0,4}A_{4,2}\ &\vdots\ A_{4,4} &\to A_{4,0}A_{0,4} \vert A_{4,1} A_{1,4} \vert A_{4,2}A_{2,4} \vert A_{4,3}A_{3,4} \vert A_{4,4}A_{4,4}\ A_{0,4} &\to A_{1,3}\ A_{1,3} &\to aA_{1,3}a\ A_{1,3} &\to bA_{1,3}b\ A_{1,3} &\to aA_{1,1}\ A_{1,3} &\to bA_{1,1} \end{align*}