While shopping at the mall, Tom bought 3 hats and 4 pairs of glasses and spent $123. His friend Jerry bought the same type of items consisting of 1 hat and 3 pairs of glasses and spent $66. How much does a pair of glasses cost? How much does a hat cost?