Read problems statements in Mandarin Chinese  and Russian. 
Chef and his friend Yurii decided to meet in the cafe. As they are very busy one would not wait for another too long. Namely, after arriving, Chef will spend at most  t_{1} seconds waiting for Yurii while Yurii will wait no more than t_{2} seconds.
Chef can arrive at any moment within [0..T_{1}] with equal probability. Similarly Yurii can arrive at any moment within [0..T_{2}].
Arrival time may be any real number from the interval.
Chef asks you to calculate the probability of meeting his friend Yurii in the cafe.

------ Input ------ 

First line of the input contains an integer T denoting the number of test cases. First and the only line of each test case contains four space-separated integers – T_{1}, T_{2}, t_{1} and t_{2}.

------ Output ------ 

For each test case, output one the single real number - probability of meeting Chef and his friend Yurii. The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}.

------ Constraints ------ 

$1 ≤ T ≤ 10^{5}$
$1 ≤ T_{1}, T_{2}  ≤ 10^{9} $
$0 ≤ t_{1}, t_{2}  ≤ 10^{9} $

Subtask 1: (5 points)

$t_{1} = 0 and t_{2} = 0$

Subtask 2: (15 points)

$t_{1} = 0 or t_{2} = 0$

Subtask 3: (25 points)

$1 ≤ T ≤ 5$
$1 ≤ T_{1}, T_{2} ≤ 10$
$The answer will be considered correct if its absolute or relative error doesn't exceed 10^{-2}$

Subtask 4: (55 points)

$Original constraints$

----- Sample Input 1 ------ 
2
2 2 1 1
1 1 1 1
----- Sample Output 1 ------ 
0.750000
1.000000

Difficulty: MEDIUM_HARD
Tags: Mathematics

Implementation

Probability

Starter code:

Solutions:
for case in range(int(input())):
	(a, b, c, d) = [int(x) for x in input().split()]
	if a < b:
		(a, b, c, d) = (b, a, d, c)
	if c > b:
		c = b
	if d > a:
		d = a
	num = b * c - c * c / 2.0 + b * d
	if b + d > a:
		num -= (b + d - a) ** 2 / 2.0
	print(num / (a * b))


import sys
if sys.version_info > (3,):
	long = int
	xrange = range
T = int(input())
for i in range(T):
	(T1, T2, t1, t2) = list(map(int, input().split()))
	if t1 == t2 == 0 and (T1 > 0 or T2 > 0):
		print(0)
	elif t1 == 0 or t2 == 0:
		if t2 == 0:
			(T1, T2, t1, t2) = (T2, T1, t2, t1)
		Exc = 0
		if t2 > T1:
			pass
		elif T2 + t2 < T1:
			Exc += 1 - (T2 + t2) / T1 + T2 / (2 * T1)
		else:
			Exc += (T1 - t2) ** 2 / (2 * T1 * T2)
		if T2 < T1:
			Exc += T2 / (2 * T1)
		else:
			Exc += 1 - T1 / (2 * T2)
		print(1 - Exc)
	else:
		Exc = 0
		if t2 > T1:
			pass
		elif T2 + t2 < T1:
			Exc += 1 - (T2 + t2) / T1 + T2 / (2 * T1)
		else:
			Exc += (T1 - t2) ** 2 / (2 * T1 * T2)
		if t1 > T2:
			pass
		elif T2 < T1 + t1:
			Exc += (T2 - t1) ** 2 / (2 * T1 * T2)
		else:
			Exc += (T2 - t1) ** 2 / (2 * T1 * T2) - (T2 - (T1 + t1)) ** 2 / (2 * T1 * T2)
		print(1 - Exc)


import sys
t = int(input())
while t > 0:
	answer = 0.0
	input_list = [int(x) for x in input().split(' ')]
	(T1, T2, t1, t2) = (input_list[0], input_list[1], input_list[2], input_list[3])
	if t1 == 0 and t2 == 0:
		print('0')
	elif t1 == 0 or t2 == 0:
		if t1 == 0:
			if T1 >= T2:
				if t2 >= T1:
					answer = answer + T2 * (2 * T1 - T2) / 2.0
				elif T2 + t2 <= T1:
					answer = answer + t2 * T2
				else:
					answer = answer + t2 * (T1 - t2) + (T2 + t2 - T1) * (T1 + t2 - T2) / 2.0
			elif t2 >= T1:
				answer = answer + T1 * T1 / 2.0
			else:
				answer = answer + t2 * (T1 - t2) + t2 * t2 / 2.0
			answer = answer / (T1 * T2)
			print(answer)
		else:
			if T1 >= T2:
				if t1 >= T2:
					answer = answer + T2 * T2 / 2.0
				else:
					answer = answer + t1 * (T2 - t1) + t1 * t1 / 2.0
			elif t1 >= T2:
				answer = answer + T1 * (2 * T2 - T1) / 2.0
			elif T1 + t1 <= T2:
				answer = answer + t1 * T1
			else:
				answer = answer + t1 * (T2 - t1) + (T1 + t1 - T2) * (T2 + t1 - T1) / 2.0
			answer = answer / (T1 * T2)
			print(answer)
	elif T1 >= T2:
		if t1 >= T2:
			answer = answer + T2 * T2 / 2.0
		else:
			answer = answer + t1 * (T2 - t1) + t1 * t1 / 2.0
		if t2 >= T1:
			answer = answer + T2 * (2 * T1 - T2) / 2.0
		elif T2 + t2 <= T1:
			answer = answer + t2 * T2
		else:
			answer = answer + t2 * (T1 - t2) + (T2 + t2 - T1) * (T1 + t2 - T2) / 2.0
		answer = answer / (T1 * T2)
		print(answer)
	else:
		if t1 >= T2:
			answer = answer + T1 * (2 * T2 - T1) / 2.0
		elif T1 + t1 <= T2:
			answer = answer + t1 * T1
		else:
			answer = answer + t1 * (T2 - t1) + (T1 + t1 - T2) * (T2 + t1 - T1) / 2.0
		if t2 >= T1:
			answer = answer + T1 * T1 / 2.0
		else:
			answer = answer + t2 * (T1 - t2) + t2 * t2 / 2.0
		answer = answer / (T1 * T2)
		print(answer)
	t = t - 1
sys.exit(0)


import sys
import random
from decimal import *
import math
getcontext().prec = 10
arr = sys.stdin.read().split()
N = int(arr[0])
k = 1

def calc1(T1, T2, t1, t2):
	ret = 0.0
	t_sum = t1 + t2
	T1 *= 1.0
	T2 *= 1.0
	t1 *= 1.0
	t2 *= 1.0
	T2_minust1 = T2 - t1
	T1_minust1 = T1 - t1
	T2_minust2 = T2 - t2
	T1_minust2 = T1 - t2
	T1_T2 = T1 - T2
	if t1 < T2:
		ret = t2 * t1 + float(t1 ** 2 / 2)
		if T2 + t2 > T1:
			ret += t_sum * (T1_minust2 + T1_minust1 - T1) + float(t_sum ** 2 / 2)
			if T2 < T1 + t1:
				ret = ret - float((T1_T2 + t1) ** 2 / 2)
		else:
			ret += t_sum * T2_minust1
	else:
		ret = t2 * T2 + float(T2 ** 2 / 2)
	return float(ret)

def calc2(T1, T2, t1, t2):
	ret = 0.0
	T1 *= 1.0
	T2 *= 1.0
	t1 *= 1.0
	t2 *= 1.0
	t_sum = t1 + t2
	T2_minust1 = T2 - t1
	T1_minust1 = T1 - t1
	T2_minust2 = T2 - t2
	T1_minust2 = T1 - t2
	T1_T2 = T1 - T2
	if T2 + t2 > T1:
		ret = t2 * T1_minust2 + float(T1_minust2 ** 2 / 2)
		if T2 > t1:
			ret += T1 * (t2 - T1_minust1) + float(T1 ** 2 / 2)
			if T2 < T1 + t1:
				ret = ret - (T1_T2 + t1) ** 2 / 2
		else:
			ret += T1 * (t2 - T1_T2)
	else:
		ret = t2 * T2 + float(T2 ** 2 / 2)
	return float(ret)
for d in range(0, N):
	T1 = int(arr[k]) * 1.0
	k += 1
	T2 = int(arr[k]) * 1.0
	Tmul = T1 * T2 * 1.0
	k += 1
	t1 = int(arr[k]) * 1.0
	k += 1
	t2 = int(arr[k]) * 1.0
	k += 1
	ans = 0
	T1minust2 = T1 - t2
	xs = T1 + t1 - T2
	if T1 - t2 >= t1:
		ans = calc1(T1, T2, t1, t2) * 1.0
	elif T1minust2 >= 0:
		ans = calc2(T1, T2, t1, t2) * 1.0
	elif t1 < T2:
		ans = T1 * t1 + float(T1 ** 2 / 2)
		if T2 < T1 + t1:
			ans = ans - float(xs ** 2 / 2)
	else:
		ans += Tmul
	print(str(round(float(ans / Tmul), 7)))


def value(a, b):
	return b * (b + 1) / 2 - a * (a + 1) / 2
t = input()
t = int(t)
for tt in range(0, t):
	(T1, T2, t1, t2) = input().split()
	T1 = int(T1)
	T2 = int(T2)
	t1 = int(t1)
	t2 = int(t2)
	T1 = T1 * 1000000
	T2 = T2 * 1000000
	t1 = t1 * 1000000
	t2 = t2 * 1000000
	if t1 == 0 and t2 == 0:
		ans = min(T1, T2) / (T1 * T2)
	else:
		if T1 > T2:
			(t1, t2) = (t2, t1)
			(T1, T2) = (T2, T1)
		if t1 < T2:
			ans = t1 * min(T2 - t1, T1)
			if T2 - t1 < T1:
				ans = ans + value(T2 - T1, t1)
		else:
			ans = value(T2 - T1, T2)
		if t2 >= T1:
			ans = ans + value(0, T1)
		else:
			ans = ans + (T1 - t2) * t2 + value(0, t2)
	ans = ans / (T1 * T2)
	print(ans)


a = int(input())
while a > 0:
	a -= 1
	b = input()
	(T1, T2, t1, t2) = [int(n) for n in b.split()]
	s = 1.0
	f = 0
	if t2 < T1:
		k = min(T1 - t2, T2)
		f += 0.5 * k * k
		if T1 - t2 > T2:
			f += T2 * (T1 - T2 - t2)
	if t1 < T2:
		k = min(T2 - t1, T1)
		f += 0.5 * k * k
		if T2 - t1 > T1:
			f += T1 * (T2 - T1 - t1)
	s -= f / (T1 * T2)
	print('{0:.6f}'.format(s))


t = int(input())
while t:
	t -= 1
	(T1, T2, t1, t2) = map(int, input().split())
	if T1 < T2:
		(T1, T2, t1, t2) = (T2, T1, t2, t1)
	if t1 == 0 and t2 == 0:
		ans = 0
	elif t1 >= T2 and t2 >= T1:
		ans = 1
	elif t1 >= T2:
		if T2 + t2 >= T1:
			ans = 1 - 0.5 * (T1 - t2) ** 2 / (T1 * T2)
		else:
			ans = 1 - 0.5 * T2 * (T1 - t2 + T1 - T2 - t2) / (T1 * T2)
	elif t2 >= T1:
		ans = 1 - 0.5 * (T2 - t1) ** 2 / (T1 * T2)
	elif T2 + t2 >= T1:
		ans = 1 - (0.5 * (T2 - t1) ** 2 + 0.5 * (T1 - t2) ** 2) / (T1 * T2)
	else:
		ans = 1 - (0.5 * (T2 - t1) ** 2 + 0.5 * T2 * (T1 - t2 + T1 - T2 - t2)) / (T1 * T2)
	print('{0:.8f}'.format(ans))


def sumGeo(n):
	return n * (n + 1) // 2

def f():
	(T1, T2, t1, t2) = [int(x) for x in input().split()]
	if T1 > T2:
		(T1, T2) = (T2, T1)
		(t1, t2) = (t2, t1)
	k = 10 ** 10
	T1 *= k
	T2 *= k
	t1 *= k
	t2 *= k
	leftEndPoint = min(t1, T2) + 1
	rightEndPoint = min(T1 + t1, T2) - max(0, T1 - t2) + 1
	maxPoints = min(T2 + 1, t1 + t2 + 1)
	leftStart = maxPoints - leftEndPoint
	rightStart = T1 - (maxPoints - rightEndPoint)
	count = 0
	if leftStart <= rightStart:
		count += sumGeo(maxPoints - 1) - sumGeo(leftEndPoint - 1)
		count += sumGeo(maxPoints - 1) - sumGeo(rightEndPoint - 1)
		count += (rightStart - leftStart + 1) * maxPoints
	else:
		diff = abs(leftEndPoint - rightEndPoint)
		a = 0
		b = T1
		if leftEndPoint < rightEndPoint:
			a += diff
		else:
			b += diff
		mid = (a + b) // 2
		count += sumGeo(leftEndPoint + mid) - sumGeo(leftEndPoint - 1)
		count += sumGeo(rightEndPoint + (T1 - mid) - 1) - sumGeo(rightEndPoint - 1)
	print(count / ((T1 + 1) * (T2 + 1)))

def main():
	T = int(input())
	for t in range(T):
		f()
main()