Commute War (Large)

Choose connecting services to minimize expected travel time when departures leave hourly and each ride faces repeated random inspection delays.

Hard8Shortest pathProbabilityDynamic programmingNo attempts yetTime limit5sMemory limit512 MB

Problem

Yeongsu starts his first job next week. Seoul has dense public transit, but for some reason the police now inspect every service. To avoid being late, Yeongsu collected the timetable and the expected delay of every service along the junctions between his home and the office. Find the expected time it takes him to reach the office.

The junctions are numbered 00 through N1N-1. Service ii runs like this.

  • It leaves its origin junction AiA_i at minute SiS_i of every hour, that is at times SiS_i, Si+60S_i + 60, Si+120S_i + 120, ..., where time is measured in minutes.
  • The ride to its destination junction BiB_i takes RiR_i minutes.
  • The police inspect the vehicle during the ride. The inspection itself takes no time, but with probability PiP_i% something is wrong and the vehicle is delayed by DiD_i minutes. When the delay ends the same inspection happens again, and again it delays the vehicle by DiD_i minutes with probability PiP_i%. The inspection repeats without limit until it passes. If the delay happens kk times, the ride takes Ri+k×DiR_i + k \times D_i minutes from departure to arrival.
  • Once Yeongsu boards, he cannot get off before the destination junction.

A service with Pi=100P_i = 100 never passes the inspection, so it never reaches its destination junction.

Yeongsu is at junction HH, where his home is, at time 00, and the office is at junction OO. If he is at a junction exactly at the departure time of a service leaving that junction, he boards it without waiting. Every time he reaches a junction he knows the current time, and he takes the service that minimizes the expected remaining time. If the home and the office are the same junction, the time is 00.

Input

The first line has the number of test cases TT. Each test case has the following form.

N M H O
A[0] B[0] S[0] R[0] D[0] P[0]
...
A[M-1] B[M-1] S[M-1] R[M-1] D[M-1] P[M-1]

The first line of a test case has four integers. NN is the number of junctions, MM is the number of services, HH is the junction of the home, and OO is the junction of the office. Each of the next MM lines describes one service with six integers, in order: the origin junction AiA_i, the destination junction BiB_i, the departure minute SiS_i, the ride time RiR_i, the delay DiD_i, and the delay probability PiP_i given as a percentage.

Limits

  • 1T1001 \le T \le 100
  • 2N1002 \le N \le 100
  • 0MN×(N1)0 \le M \le N \times (N - 1)
  • 0H,O,Ai,Bi<N0 \le H, O, A_i, B_i < N
  • 0Si590 \le S_i \le 59
  • 1Ri1001 \le R_i \le 100
  • 1Di1001 \le D_i \le 100
  • 0Pi1000 \le P_i \le 100
  • AiBiA_i \ne B_i for every ii
  • AiAjA_i \ne A_j or BiBjB_i \ne B_j for every pair with i<ji < j

Output

For each test case, print one line of the form Case #x: y. xx is the test case number starting from 11, and yy is the expected time to reach the office, rounded to seven decimal places. Always print seven digits after the decimal point. If the office cannot be reached, print -1 in place of yy, with no decimal point.