Tommy had cupcakes and Elijah had croissants. Both gave half of what they had to each other. Tommy sold 8 cupcakes and Elijah sold 36 croissants. In the end, the ratios of cupcakes to croissants for Tommy and Elijah were 1 : 7 and 1 : 5 respectively. How many cupcakes did Tommy have at first?