The road construction in City A consists of

intersections with traffic lights (numbered from

to

) and

bidirectional roads.
Here are the rules:
1. All vehicles travel at maximum speed.
2. Starting from 0 seconds, traffic lights at all intersections alternate between green, yellow, and red signals. When a vehicle arrives, it can pass if the light is green or yellow; otherwise, it must stop immediately. Specifically, if the light turns green at the moment of arrival, vehicles can pass. If the light turns red at the moment of arrival, vehicles cannot pass.
3. Each intersection's traffic light has three parameters

, representing the durations of green, yellow, and red lights, respectively. The transition of traffic lights does not consume time.
4. It takes 5 seconds for a vehicle to accelerate from a standstill to maximum speed. During this period, the vehicle's speed is 0. The transition of traffic lights during the acceleration process is not considered.
If a vehicle departs from intersection

at time 0, the task is to find the shortest time to reach intersection

. It is guaranteed that any two intersections in City A can be reached through roads.