Riley plans to drive from City A to City B, which are 240 miles apart. She drives the first 60 miles at an average speed of 30 miles per hour. For the next 120 miles, she increases her speed to 60 miles per hour. Finally, she drives the remaining distance at 40 miles per hour. How long does it take Riley to travel from City A to City B? Let's think step by step and output the final answer within \boxed{}.
user