This page is still under construction.

Parts of this page are still being built. What you see may change.

Two Snails

Time limit2sMemory limit256 MB

Summary
Two snails crawl up and slide down on a 12-hour day/night cycle; find the total time over z hours when the first snail is higher than the second.
Level

Medium4 of 10

Topics
Math, Simulation, Implementation, Prefix sum
Solved
No attempts yet

Problem

Vasya sat by a window and noticed two snails on a pole, crawling upward. Vasya began watching them. He noticed that in one hour the first snail climbs a1a_1 centimeters and the second snail climbs a2a_2 centimeters.

The next morning Vasya noticed that the snails were lower than they had been in the evening. He realized that during the night the first snail slides down b1b_1 centimeters per hour and the second snail slides down b2b_2 centimeters per hour.

zz hours passed since the start of the observation, and Vasya wondered: during what period of time was the first snail higher than the second over these zz hours?

Vasya decided to assume that the snails move at their respective constant speeds both day and night, and that day and night each last 12 hours. The observation started at the beginning of the day, when the snails were at the same height. The height of the pole and the initial positions of the snails are such that the snails never leave the bounds of the pole.

Input

The first line contains a positive integer tt (1≤t≤1041 \le t \le 10^4), the number of test cases in the input. The descriptions of the test cases follow.

Each test case contains five positive integers a1a_1, b1b_1, a2a_2, b2b_2, and zz (1≤a1,b1,a2,b2≤1001 \le a_1, b_1, a_2, b_2 \le 100, 1≤z≤1051 \le z \le 10^5), the speeds of the snails and the time period Vasya is interested in.

The sum of zz over all test cases is guaranteed not to exceed 10610^6.

Output

Output tt lines. For each test case, output a single real number xx, the time during which the first snail was higher than the second. Print each number on its own line. All numbers must be printed with an absolute or relative error of at most 10−610^{-6}.

Note that printing long double values in C++ does not work correctly in the compiler version used by the judges. We apologize and will try to fix this as soon as possible, but for now we recommend using the double type.

Examples1

  1. Example 1

    Input
    5
    2 1 2 1 25
    2 3 1 1 100
    2 3 5 5 11
    3 9 2 4 15
    3 9 2 4 13
    
    Expected output
    0
    18
    0
    14.4
    13