A restaurant with two locations buys twelve bags of flour and eight large bags of sugar. Location A receives seven bags of flour and five bags of sugar for a total cost of $584. Location B receives five bags of flour and three bags of sugar for a total cost of $384. What is the cost of each bag of flour and each bag of sugar?