As Bram28 says, you need to ensure the parenthesi group operations correctly.
You need to ensure the $r$ is grouped in the antecedant. Operator precedance of $\to$ over $\wedge$ means that $R\wedge P\to Q$ is actually $R~\wedge~(P\to Q)$, when you want $(R\wedge P)~\to~Q$.
$$\Big(r\wedge \big(\exists z~\exists j : (z\neq j)\wedge (p_z=p_j)\big)\Big)~\to~q$$
This is okay, however, not everyone accepts that the "such that" notation, "$(\mathcal Q x:\ldots)$", elevates everything between the colon and the enbrace into the scope of the embraced quantifiers, so for added clarity the scope of the quantifiers could be parenthesised thusly:
$$\Big(r~\wedge ~\exists z~\exists j~\big( (z\neq j)\wedge (p_z=p_j)\big)\Big)~\to~q$$