Work backwards. At the third shop he was given as much money as he had, spent $16, and had nothing left. So after having been given "as much money as he had" he must have had $16 so he must have come into the store with $16/2= $8 and been given $8.
Now go back to the second store. He was given as much money as he had, spent $16, and had $8 left. Before spending the $16 he must have had $16+ $8= $24. That means he came into the store with $24/2= $12 and been given $12.
Finally, the first store. He was given as much money as he had, spent $16, and had $12 left. How much money did he have before spending the $16? How much was he given and how much did he come into the store with?