Is substitution done to all occurrences?
A single substitution is one application of one rule. So the rule $A\to AA$ means "Pick any single $A$ in the string and replace it with&nbsp;$AA$" and "$A\to a$" means "Pick any single $A$ and replace it with&nbsp;$a$."  Substitutions are done one at a time, and there's no way to write a rule that says "Replace every $X$ with&nbsp;$Y$, or replace them all with&nbsp;$Z$."

If you start with&nbsp;$A$ and apply the first rule, you certainly get&nbsp;$AA$, since there's no other choice. But there are two ways of applying $A\to a$ to&nbsp;$AA$: you could pick the first or second&nbsp;$A$ to replace with&nbsp;$a$.

Indeed, there are two ways to apply $A\to AA$ to the string $AA$. However, replacing either the first or second&nbsp;$A$ with $AA$ gives the string $AAA$.