A bakery sold apple pies for $10 and blueberry pies for $14. One Saturday they sold a total of 39 pies and collected a total of $458. How many apple pies did they sell and how many blueberry pies did they sell?