Commute War (Small)

Walk the single chain of hourly rides from home to the office, adding each wait, ride time, and geometric checkpoint delay for the expected arrival time.

Easy3ProbabilitySimulationMathInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Yeongsu starts his first job next week. Public transport in Seoul is dense, but every vehicle now has to pass a police checkpoint. To avoid being late on his first day, Yeongsu collected the timetable and the expected delay of every ride on the way to the office. Find the expected time at which he reaches the office.

One ride behaves like this.

  • It leaves its origin stop at minute SS of every hour, that is at times SS, S+60S+60, S+120S+120, and so on. If Yeongsu is at the origin stop at time tt, he boards the earliest departure at time tt or later. A departure exactly at time tt counts.
  • Reaching the destination stop takes RR minutes.
  • The police check the vehicle during the trip. The check itself costs no time, but with probability PP percent something is wrong and the vehicle is held for DD minutes. After those DD minutes the check runs again and can hold the vehicle again with the same probability. The check repeats until it passes. If the check finds a problem kk times, the trip takes R+D×kR + D \times k minutes.
  • Once aboard, Yeongsu cannot get off before the destination stop.

A ride with P=100P = 100 never passes the check, so it never reaches its destination stop.

Yeongsu leaves home at time 00, and at every stop he takes the ride that minimizes the expected arrival time.

Input

The first line has the number of test cases TT.

The first line of each test case has four integers NN, MM, HH, OO separated by spaces. NN is the number of stops, MM is the number of rides, HH is the stop where his home is, and OO is the stop where the office is.

Each of the next MM lines has six integers AiA_i, BiB_i, SiS_i, RiR_i, DiD_i, PiP_i for one ride. AiA_i is the origin stop, BiB_i is the destination stop, SiS_i is the minute of each hour at which the ride departs, RiR_i is the travel time, DiD_i is the length of one delay, and PiP_i is the probability that a check finds a problem. PiP_i is a percentage.

Constraints

  • 1T1001 \le T \le 100
  • 2N1002 \le N \le 100
  • 0MN10 \le M \le 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
  • Bi=Ai+1B_i = A_i + 1 for every ii
  • AiAjA_i \ne A_j or BiBjB_i \ne B_j for every pair i<ji < j, so at most one ride leaves each stop

Output

For each test case print one line in the form Case #x: y, where xx is the test case number starting at 11.

If Yeongsu can reach the office, yy is the expected arrival time rounded to seven digits after the decimal point, with all seven digits printed, so an expectation that is exactly an integer still carries seven zeros after the point. If he cannot reach the office, print -1 in place of yy, with no decimal point. When H=OH = O the expectation is 00, so print 0.0000000.