A bicyclist rides his bike each day on a trail not far from his house. During the first part of the ride he is pedaling mostly uphill and his average speed is 6 miles an hour. After a certain point, he is traveling mostly downhill and averages 15 miles per hour. If the total distance he travels is 30 miles and the total time he rides is 4 hours, how long did he ride at each speed?