Priority order of attack of grignard reagents on functional groups
For the compound given in the question, the priority order of Grignard reagent attack follows,
$\ce{R-OH &gt; R-CO-R' &gt; R-COOR'}$
Reason:

Acid-base neutralisation are very fast.

Carbonyl carbon is more nucleophilic than carboxylic carbon, as the latter one is stabilized by resonance.



Therefore, first alcohol is attacked and hence P is (a), then the carbonyl part is attacked and hence Q is (b).
Finally, one more mole of RMgX gets used up on the carboxyl part, hence R is not (d).