Fergus and Fiona are siblings, both preparing for the upcoming Caber
Tossing tournament. If you aren't familiar with the sport,
caber tossing involves holding a
large thin log (called a caber) upright,
then tossing it so that it flips once in the air before
landing "in-line" with the thrower, like the hour hand facing 12:00 on a clock.
Indeed, a bad throw would land perpendicular to the thrower, being scored a
9:00 or 3:00.
As Fergus and Fiona are both still children, instead of tossing actual logs in an open field they must make do with tossing broom handles in their mother's back garden. As they are quite unexperienced at "broom-handle" tossing, when they toss one it will land in some random position and orientation regardless of where they are aiming. Additionally their mother's garden contains evenly-spaced rows of plants which they must not disturb or else they'll get in trouble.
Rows of plants are shown as green lines. The red "caber" overlaps a row, whereas the blue "caber" does not.
Given that the broom handles are of length B centimeters and the rows of plants are
spaced apart by R centimeters between rows, what is the probability that any given toss
will land a broom handle overlapping a row of plants?
For the sake of the problem, assume that the size of the garden is unbounded and
that a broom handle's position and orientation are random.
Assume that the broom handle is a zero-width line with only length. Likewise a
row of plants is only a line with zero width.
Input Data
First line will be Q, the quantity of testcases.
Q lines will follow, each with two space-separated integers in the format B R.
Answer
Should consist of Q space-separated values corresponding to the probability of
a broom handle landing on a row of plants for any given toss.
Report probabilities as a decimal. For example, a 50% chance is reported as 0.5.
Error should be less than 1e-6.
Example
input data:
3
123 123
1234 5678
24680 13579
answer:
0.63662 0.138357 0.819980