Coin tossing

Given head counts from tossing two coins whose head probabilities are independent uniform on [0,1], compute the probability that the first coin's probability is smaller.

Medium7ProbabilityMathDynamic programmingImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

A machine makes coins that land heads with probability pp and tails with probability 1p1-p. Here pp is a number between 0 and 1, and the machine has no setting for it. The machine picks pp at random while it makes a coin, so pp is uniform on the interval [0,1][0, 1].

The machine made two coins. Coin 1 has probability pp and coin 2 has probability qq. Both pp and qq are uniform on [0,1][0, 1] and independent of each other, and there is no way to read off their actual values.

Coin 1 was tossed n1n_1 times and came up heads m1m_1 times. Coin 2 was tossed n2n_2 times and came up heads m2m_2 times. Given these observations, write a program that computes the probability that p<qp < q.

Input

The first line contains the number of test cases TT (1T1000001 \le T \le 100000).

Each of the next TT lines holds one test case: n1n_1, m1m_1, n2n_2, m2m_2, separated by spaces. (1n1,n210001 \le n_1, n_2 \le 1000, 0m1,m2500 \le m_1, m_2 \le 50, m1n1m_1 \le n_1, m2n2m_2 \le n_2)

Output

For each test case, print the probability that p<qp < q on its own line. Round at the seventh decimal place and print exactly six digits after the decimal point. For example, print 0.800000 when the probability is 45\frac{4}{5}.