We complete the multiplication table for $S$, under the assumption that the product of two things in $S$ is also in $S$. (That fact was not explicitly mentioned.)
Could we have $qr=p$? Then $(qr)r=pr=r$. But $(qr)r=q(rr)=qr=p$. That would make $(qr)r$ simultaneously equal to $p$ and $r$, which is impossible.
That leaves the possibilities $qr=q$ and $qr=r$. Suppose first that $qr=q$. Then let $b=q$. We have by the rules $qp=q$, $qq=q$, and $qr=q$, and we are finished.
By symmetry, if $qr=r$ then we can take $b=r$. Or else we can more or less repeat the previous argument, interchanging the roles of $q$ and $r$.
Remark: But we really ought to check that we have not been lied to, that if for example we complete the multiplication by $qr=q$, all the given rules will be satisfied. After all, we could have been given a collection of "rules" that turn out to be inconsistent.
The only thing that really needs checking is $4$). That takes some work. In principle we need to check that $a(bc)=(ab)c$ for all $27$ triples $(a,b,c)$. With some thinking we can cut it down to a lot less checking than that. If there is at least one $p$ among $a$, $b$, and $c$, verification is easy. so we only need to worry when each of $a$, $b$, $c$ is $q$ or $r$. So we are down to $8$ cases, easily checked.