After defeating a Blacklist Rival, you get a chance to draw $1$ reward slip out of $x$ hidden valid slips. Initially, $x=3$ and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are $c$, $m$, and $p$, respectively. There is also a volatility factor $v$. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the $x$ valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was $a$. Then,

If the item was a Pink Slip, the quest is over, and you will not play any more races.

Otherwise,

If $a\leq v$, the probability of the item drawn becomes $0$ and the item is no longer a valid item for all the further draws, reducing $x$ by $1$. Moreover, the reduced probability $a$ is distributed equally among the other remaining valid items.

If $a > v$, the probability of the item drawn reduces by $v$ and the reduced probability is distributed equally among the other valid items.

For example,

If $(c,m,p)=(0.2,0.1,0.7)$ and $v=0.1$, after drawing Cash, the new probabilities will be $(0.1,0.15,0.75)$.

If $(c,m,p)=(0.1,0.2,0.7)$ and $v=0.2$, after drawing Cash, the new probabilities will be $(Invalid,0.25,0.75)$.

If $(c,m,p)=(0.2,Invalid,0.8)$ and $v=0.1$, after drawing Cash, the new probabilities will be $(0.1,Invalid,0.9)$.

If $(c,m,p)=(0.1,Invalid,0.9)$ and $v=0.2$, after drawing Cash, the new probabilities will be $(Invalid,Invalid,1.0)$.

You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.


-----Input-----

The first line of input contains a single integer $t$ ($1\leq t\leq 10$)  — the number of test cases.

The first and the only line of each test case contains four real numbers $c$, $m$, $p$ and $v$ ($0 < c,m,p < 1$, $c+m+p=1$, $0.1\leq v\leq 0.9$).

Additionally, it is guaranteed that each of $c$, $m$, $p$ and $v$ have at most $4$ decimal places.


-----Output-----

For each test case, output a single line containing a single real number — the expected number of races that you must play in order to draw a Pink Slip.

Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$.

Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$.


-----Examples-----

Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896


-----Note-----

For the first test case, the possible drawing sequences are:

P with a probability of $0.6$;

CP with a probability of $0.2\cdot 0.7 = 0.14$;

CMP with a probability of $0.2\cdot 0.3\cdot 0.9 = 0.054$;

CMMP with a probability of $0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$;

MP with a probability of $0.2\cdot 0.7 = 0.14$;

MCP with a probability of $0.2\cdot 0.3\cdot 0.9 = 0.054$;

MCCP with a probability of $0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$.

So, the expected number of races is equal to $1\cdot 0.6 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 = 1.532$.

For the second test case, the possible drawing sequences are:

P with a probability of $0.4$;

CP with a probability of $0.4\cdot 0.6 = 0.24$;

CMP with a probability of $0.4\cdot 0.4\cdot 1 = 0.16$;

MP with a probability of $0.2\cdot 0.5 = 0.1$;

MCP with a probability of $0.2\cdot 0.5\cdot 1 = 0.1$.

So, the expected number of races is equal to $1\cdot 0.4 + 2\cdot 0.24 + 3\cdot 0.16 + 2\cdot 0.1 + 3\cdot 0.1 = 1.86$.

Source: codeforces | Difficulty: HARD
Tags: Bit manipulation

Graph traversal

Probability

Implementation

Complete search

Mathematics


Solutions:
def rec(c, m, p, v):
	ret = 0
	ret += p * 0
	if 0 < m <= v + 1e-05:
		tmp = 0
		if c > 0:
			tmp = rec(c + m / 2, 0, p + m / 2, v)
		else:
			tmp = rec(0, 0, 1, v)
		ret += m * tmp
	elif m > v:
		tmp = 0
		if c > 0:
			tmp = rec(c + v / 2, m - v, p + v / 2, v)
		else:
			tmp = rec(0, m - v, p + v, v)
		ret += m * tmp
	if 0 < c <= v + 1e-05:
		tmp = 0
		if m > 0:
			tmp = rec(0, m + c / 2, p + c / 2, v)
		else:
			tmp = rec(0, 0, 1, v)
		ret += c * tmp
	elif c > v:
		tmp = 0
		if m > 0:
			tmp = rec(c - v, m + v / 2, p + v / 2, v)
		else:
			tmp = rec(c - v, 0, p + v, v)
		ret += c * tmp
	return ret + c + m
t = int(input())
for case in range(t):
	(c, m, p, v) = map(float, input().split())
	print(1 + rec(c, m, p, v))


def calc(a, v):
	n = len(a)
	ans = 0
	for i in range(n):
		if a[i] > v + 1e-10:
			b = a.copy()
			b[i] -= v
			if n == 2:
				b[1 - i] += v / n
			ans += (calc(b, v) + 1) * a[i]
		elif n == 2:
			ans += (calc([a[1 - i] + a[i] / 2], v) + 1) * a[i]
		else:
			ans += (1 + 1) * a[i]
	ans += 1 * (1 - sum(a))
	return ans

def solve_case():
	a = list(map(float, input().split()))
	print(f'{calc(a[:2], a[-1]):.12f}')
n = int(input())
for i in range(n):
	solve_case()


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
mod = 10 ** 9 + 7

def solve(c, m, p, v, count, pp):
	global ans
	ans += (count + 1) * (p * pp) / 100000
	if c == 0 and m == 0:
		return
	if c:
		if c > v:
			if m > 0:
				solve(c - v, m + v / 2, p + v / 2, v, count + 1, pp * c / 100000)
			else:
				solve(c - v, m, p + v, v, count + 1, pp * c / 100000)
		elif m > 0:
			solve(0, m + c / 2, p + c / 2, v, count + 1, pp * c / 100000)
		else:
			solve(0, m, p + c, v, count + 1, pp * c / 100000)
	if m:
		if m > v:
			if c:
				solve(c + v / 2, m - v, p + v / 2, v, count + 1, pp * m / 100000)
			else:
				solve(c, m - v, p + v, v, count + 1, pp * m / 100000)
		elif c:
			solve(c + m / 2, 0, p + m / 2, v, count + 1, pp * m / 100000)
		else:
			solve(c, 0, p + m, v, count + 1, pp * m / 100000)
global ans
for _ in range(int(input())):
	(c, m, p, v) = map(lambda x: float(x) * 100000, input().split())
	ans = 0.0
	solve(c, m, p, v, 0, 100000)
	print(ans / 100000)


def solve():
	(c, m, p, v) = map(float, input().split())

	def rec1(a, p, cur, r):
		cur += 1
		ans = cur * p * r
		if a > 1e-08:
			if a >= v:
				ans += rec1(a - v, p + v, cur, r * a)
			else:
				ans += rec1(0, p + a, cur, r * a)
		return ans

	def rec(c, m, p, cur, r):
		cur += 1
		ans = cur * p * r
		if c > 1e-08:
			if c > v + 1e-09:
				ans += rec(c - v, m + v / 2, p + v / 2, cur, r * c)
			else:
				ans += rec1(m + c / 2, p + c / 2, cur, r * c)
		if m > 1e-08:
			if m > v + 1e-09:
				ans += rec(c + v / 2, m - v, p + v / 2, cur, r * m)
			else:
				ans += rec1(c + m / 2, p + m / 2, cur, r * m)
		return ans
	print(f'{rec(c, m, p, 0, 1):.{9}f}')
k = int(input())
for i in range(k):
	solve()


def cal(a, b, c, v, sl):
	if a == 0 and b == 0:
		return c * sl
	res = 0
	if a > 1e-08:
		l = min(a, v)
		if b > 1e-08:
			res += a * cal(a - l, b + l / 2, c + l / 2, v, sl + 1)
		else:
			res += a * cal(a - l, 0, c + l, v, sl + 1)
	if b > 1e-08:
		l = min(b, v)
		if a > 1e-08:
			res += b * cal(a + l / 2, b - l, c + l / 2, v, sl + 1)
		else:
			res += b * cal(0, b - l, c + l, v, sl + 1)
	return sl * c + res
n = int(input())
for i in range(n):
	(a, b, c, v) = map(float, input().split())
	print(cal(a, b, c, v, 1))


SCALE = 1000000.0

def find_odds(c: float, m: float, p: float, v: float, cumulative: float=SCALE, depth=1) -> float:
	total = cumulative / SCALE * p / SCALE * depth
	if c > 0:
		new_c = max(0.0, c - v)
		delta = c - new_c
		if m > 0:
			new_p = p + 0.5 * delta
			new_m = m + 0.5 * delta
		else:
			new_p = p + delta
			new_m = 0
		total += find_odds(new_c, new_m, new_p, v, cumulative * c / SCALE, depth + 1)
	if m > 0:
		new_m = max(0.0, m - v)
		delta = m - new_m
		if c > 0:
			new_p = p + 0.5 * delta
			new_c = c + 0.5 * delta
		else:
			new_p = p + delta
			new_c = 0
		total += find_odds(new_c, new_m, new_p, v, cumulative * m / SCALE, depth + 1)
	return total
for _ in range(int(input())):
	(c, m, p, v) = [float(i) for i in input().split(' ')]
	print(find_odds(c * SCALE, m * SCALE, p * SCALE, v * SCALE))


import sys
from bisect import bisect_left as lb
from collections import deque
from queue import PriorityQueue as pq
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
ans = 0

def f(c, m, p, v, t, cnt):
	global ans
	if c > 0:
		x = min(c, v)
		if abs(c - x) < 10 ** (-10):
			x = c
		if m > 0:
			f(c - x, m + x / 2, p + x / 2, v, t * c, cnt + 1)
		else:
			f(c - x, 0, p + x, v, t * c, cnt + 1)
	if m > 0:
		x = min(m, v)
		if abs(m - x) < 10 ** (-10):
			x = m
		if c > 0:
			f(c + x / 2, m - x, p + x / 2, v, t * m, cnt + 1)
		else:
			f(0, m - x, p + x, v, t * m, cnt + 1)
	ans += t * p * cnt
for _ in range(ii()):
	(c, m, p, v) = ilf()
	ans = 0
	f(c, m, p, v, 1, 1)
	print(ans)


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
mndif = 10 ** (-6)

def solve(curr, currp, c, m, p, v):
	ans = (curr + 1) * currp * p
	if c < mndif and m < mndif:
		return ans
	if c < mndif:
		if m > v:
			ans += solve(curr + 1, currp * m, 0, m - v, p + v, v)
		else:
			ans += solve(curr + 1, currp * m, 0, 0, p + m, v)
		return ans
	if m < mndif:
		if c > v:
			ans += solve(curr + 1, currp * c, c - v, 0, p + v, v)
		else:
			ans += solve(curr + 1, currp * c, 0, 0, p + c, v)
		return ans
	if c > v:
		ans += solve(curr + 1, currp * c, c - v, m + v / 2, p + v / 2, v)
	else:
		ans += solve(curr + 1, currp * c, 0, m + c / 2, p + c / 2, v)
	if m > v:
		ans += solve(curr + 1, currp * m, c + v / 2, m - v, p + v / 2, v)
	else:
		ans += solve(curr + 1, currp * m, c + m / 2, 0, p + m / 2, v)
	return ans
for _ in range(int(inp())):
	(c, m, p, v) = map(float, inp().split())
	ans = solve(0, 1, c, m, p, v)
	print(ans)


scale = 10 ** 6

def calculate_expectation(c, m, p, v):
	expectation = 1
	if c != 0:
		if c <= v:
			if m != 0:
				expectation += c / scale * calculate_expectation(0, m + c / 2, p + c / 2, v)
			else:
				expectation += c / scale
		elif m != 0:
			expectation += c / scale * calculate_expectation(c - v, m + v / 2, p + v / 2, v)
		else:
			expectation += c / scale * calculate_expectation(c - v, 0, p + v, v)
	if m != 0:
		if m <= v:
			if c != 0:
				expectation += m / scale * calculate_expectation(c + m / 2, 0, p + m / 2, v)
			else:
				expectation += m / scale
		elif c != 0:
			expectation += m / scale * calculate_expectation(c + v / 2, m - v, p + v / 2, v)
		else:
			expectation += m / scale * calculate_expectation(0, m - v, p + v, v)
	return expectation
t = int(input())
results = []
for i in range(t):
	(c, m, p, v) = map(float, input().split())
	c = c * scale
	m = m * scale
	p = p * scale
	v = v * scale
	results.append(calculate_expectation(c, m, p, v))
for i in range(t):
	print(results[i])


from decimal import Decimal
from functools import lru_cache
eps = Decimal(1e-06)
prec = 6

@lru_cache
def g(c, p, v):
	if abs(p - 1) <= eps:
		return Decimal(1)
	res = Decimal(1)
	if c <= v:
		res += c
	else:
		res += c * g(c - v, p + v, v)
	return res

@lru_cache
def f(c, m, p, v):
	if abs(p - 1) <= eps:
		return Decimal(1)
	res = Decimal(1)
	if m <= v:
		res += m * g(c + m / 2, p + m / 2, v)
	else:
		res += m * f(c + v / 2, m - v, p + v / 2, v)
	if c <= v:
		res += c * g(m + c / 2, p + c / 2, v)
	else:
		res += c * f(c - v, m + v / 2, p + v / 2, v)
	return res

def solve():
	(c, m, p, v) = map(Decimal, input().split())
	return f(c, m, p, v)

def main():
	t = int(input())
	for i in range(t):
		print(solve())
main()


import sys
sys.setrecursionlimit(10 ** 9)
SCALE = 10 ** 6

def func(it):
	return float(SCALE * float(it))

def solve(c, m, p, v):
	ans = p / SCALE
	if c > 0:
		if c > v:
			if m > 0:
				ans += c / SCALE * (1 + solve(c - v, m + v / 2, p + v / 2, v))
			else:
				ans += c / SCALE * (1 + solve(c - v, 0, p + v, v))
		elif m > 0:
			ans += c / SCALE * (1 + solve(0, m + c / 2, p + c / 2, v))
		else:
			ans += c / SCALE * (1 + solve(0, 0, p + c, v))
	if m > 0:
		if m > v:
			if c > 0:
				ans += m / SCALE * (1 + solve(c + v / 2, m - v, p + v / 2, v))
			else:
				ans += m / SCALE * (1 + solve(0, m - v, p + v, v))
		elif c > 0:
			ans += m / SCALE * (1 + solve(c + m / 2, 0, p + m / 2, v))
		else:
			ans += m / SCALE * (1 + solve(0, 0, p + m, v))
	return ans
for case in range(int(input())):
	mp = map(func, input().split())
	ans = solve(*mp)
	print(round(ans, 12))


def rec(races, idx, choices, v):
	if idx == 2:
		return races
	ch = choices.copy()
	reduce = min(ch[idx], v)
	ch[idx] -= reduce
	(cn, ci) = (0, 0)
	for i in range(3):
		if i != idx and ch[i] > 0:
			cn += 1
			ci = i
			ch[i] += reduce / 2
		if ch[i] < 1e-05:
			ch[i] = 0
	if cn == 0:
		return races
	elif cn == 1:
		ch[ci] += reduce / 2
	res = 0
	for i in range(3):
		if ch[i] > 0:
			res += ch[i] * rec(races + 1, i, ch, v)
	return res

def solve(c, m, p, v):
	choices = [c, m, p, v]
	res = 0
	for i in range(3):
		res += choices[i] * rec(1, i, choices, v)
	return res
T = int(input())
for case in range(T):
	(C, M, P, V) = map(float, input().split())
	res = solve(C, M, P, V)
	print(res)


import sys
import math
from collections import deque
from bisect import bisect_left, bisect_right
I = sys.stdin.readline
II = lambda : int(I())
IN = lambda x: map(int, x.split())
FN = lambda x: map(float, x.split())
L = lambda x: list(IN(x))
M = 1000000007
P = print
T = True
F = False
mini = 1e-07

def find(c, m, p, v, r, f):
	f = round(f, 12)
	if f <= 0:
		return 0
	if m <= mini and c <= mini:
		return f * r
	if m <= mini:
		t = max(0, c - v)
		d = c - t
		return f * p * r + find(t, 0, p + d, v, r + 1, f * c)
	if c <= mini:
		t = max(0, m - v)
		return f * p * r + find(0, t, p + m - t, v, r + 1, f * m)
	t = max(0, c - v)
	d = c - t
	a = find(t, m + d / 2, p + d / 2, v, r + 1, f * c)
	t = max(0, m - v)
	d = m - t
	b = find(c + d / 2, t, p + d / 2, v, r + 1, f * m)
	return a + b + f * p * r
for _ in range(II()):
	(c, m, p, v) = FN(I())
	P(find(c, m, p, v, 1, 1))


import sys
from math import ceil
input = lambda : sys.stdin.readline().strip()
scale = 10000000.0

def solve(c, m, p, v):
	ans = p / scale
	if c > 0:
		if c > v:
			if m > 0:
				ans += c / scale * (1 + solve(c - v, m + v // 2, p + v // 2, v))
			else:
				ans += c / scale * (1 + solve(c - v, 0, p + v, v))
		elif m > 0:
			ans += c / scale * (1 + solve(0, m + c // 2, p + c // 2, v))
		else:
			ans += c / scale * (1 + solve(0, 0, p + c, v))
	if m > 0:
		if m > v:
			if c > 0:
				ans += m / scale * (1 + solve(c + v // 2, m - v, p + v // 2, v))
			else:
				ans += m / scale * (1 + solve(0, m - v, p + v, v))
		elif c > 0:
			ans += m / scale * (1 + solve(c + m // 2, 0, p + m // 2, v))
		else:
			ans += m / scale * (1 + solve(0, 0, p + m, v))
	return ans
t = int(input())
while t:
	t -= 1
	(c, m, p, v) = map(float, input().split())
	(c, m, p, v) = (ceil(c * scale), ceil(m * scale), ceil(p * scale), ceil(v * scale))
	print(solve(c, m, p, v))


import math
scale = 1000000.0

def zero(x):
	return abs(x) < 1e-09

def recur(c, m, p, v, d):
	(ca, cb, cc) = (0.0, 0.0, 0.0)
	if not zero(c) and c > v and (not zero(c - v)):
		if zero(m) and (not zero(p)):
			ca = recur(c - v, m, p + v, v, d + 1)
		elif not zero(p) and (not zero(m)):
			ca = recur(c - v, m + v / 2, p + v / 2, v, d + 1)
	elif not zero(c):
		if zero(m) and (not zero(p)):
			ca = recur(0, m, p + c, v, d + 1)
		elif not zero(p) and (not zero(m)):
			ca = recur(0, m + c / 2, p + c / 2, v, d + 1)
	if not zero(m) and m > v and (not zero(m - v)):
		if zero(c) and (not zero(p)):
			cb = recur(c, m - v, p + v, v, d + 1)
		elif not zero(c) and (not zero(p)):
			cb = recur(c + v / 2, m - v, p + v / 2, v, d + 1)
	elif not zero(m):
		if zero(c) and (not zero(p)):
			cb = recur(c, 0, p + m, v, d + 1)
		elif not zero(c) and (not zero(p)):
			cb = recur(c + m / 2, 0, p + m / 2, v, d + 1)
	if p:
		cc = p
	(c1, c2, c3) = (c if c else 0.0, m if m else 0.0, p if p else 0)
	return c1 * ca + c2 * cb + p * float(d)

def solve():
	(c, m, p, v) = tuple((float(x) for x in input().split()))
	print(recur(c, m, p, v, 1))
	return
for _ in range(int(input())):
	solve()


t = int(input())

def eşittir(a, b):
	if round(a, 9) == round(b, 9):
		return True
	return False
for i in range(t):
	(c, m, p, v) = map(float, input().split(' '))
	stack = [(c, m, p, v, 1, 1)]
	res = 0
	while len(stack) != 0:
		(c, m, p, v, dismiss, turn) = stack.pop()
		dismiss = dismiss
		if not eşittir(c, 0.0):
			crit = max(0.0, c - v)
			adder = (c - crit) / 2
			if not eşittir(m, 0.0):
				stack.append((crit, m + adder, p + adder, v, dismiss * c, turn + 1))
			else:
				stack.append((crit, 0.0, p + adder * 2, v, dismiss * c, turn + 1))
		if not eşittir(m, 0.0):
			crit = max(0.0, m - v)
			adder = (m - crit) / 2
			if not eşittir(c, 0.0):
				stack.append((c + adder, crit, p + adder, v, dismiss * m, turn + 1))
			else:
				stack.append((0.0, crit, p + adder * 2, v, dismiss * m, turn + 1))
		if p != 0:
			res += dismiss * p * turn
	print(res)


t = int(input())
ex = 0

def dfs(c, m, p, v, count, curr):
	global ex
	if p:
		ex += curr * count * p
	if c > 10 ** (-6):
		if c > v:
			if m > 10 ** (-6):
				dfs(c - v, m + v / 2, p + v / 2, v, count + 1, curr * c)
			else:
				dfs(c - v, 0, p + v, v, count + 1, curr * c)
		elif m > 10 ** (-6):
			dfs(0, m + c / 2, p + c / 2, v, count + 1, curr * c)
		else:
			dfs(0, 0, 1, v, count + 1, curr * c)
	if m > 10 ** (-6):
		if m > v:
			if c > 10 ** (-6):
				dfs(c + v / 2, m - v, p + v / 2, v, count + 1, curr * m)
			else:
				dfs(0, m - v, p + v, v, count + 1, curr * m)
		elif c > 10 ** (-6):
			dfs(c + m / 2, 0, p + m / 2, v, count + 1, curr * m)
		else:
			dfs(0, 0, 1, v, count + 1, curr * m)
for _ in range(t):
	(c, m, p, v) = list(map(float, input().rstrip().split()))
	ex = 0
	dfs(c, m, p, v, 1, 1)
	print(ex)


from sys import stdin, setrecursionlimit, maxsize
from collections import deque
from math import exp, gcd
input = stdin.readline
setrecursionlimit(10 ** 9)
eps = 1e-09
scale = 1000000.0

def expectedRaces(c, m, p, v):
	res = p / scale
	if c > 0:
		if c > v:
			if m > 0:
				res += c / scale * (1 + expectedRaces(c - v, m + v // 2, p + v // 2, v))
			else:
				res += c / scale * (1 + expectedRaces(c - v, 0, p + v, v))
		elif m > 0:
			res += c / scale * (1 + expectedRaces(0, m + c // 2, p + c // 2, v))
		else:
			res += c / scale * (1 + expectedRaces(0, 0, p + c, v))
	if m > 0:
		if m > v:
			if c > 0:
				res += m / scale * (1 + expectedRaces(c + v // 2, m - v, p + v // 2, v))
			else:
				res += m / scale * (1 + expectedRaces(0, m - v, p + v, v))
		elif c > 0:
			res += m / scale * (1 + expectedRaces(c + m // 2, m - v, p + m // 2, v))
		else:
			res += m / scale * (1 + expectedRaces(0, 0, p + m, v))
	return res
for _ in range(int(input())):
	(cd, md, pd, vd) = map(float, input().split())
	c = round(cd * scale)
	m = round(md * scale)
	p = round(pd * scale)
	v = round(vd * scale)
	res = expectedRaces(c, m, p, v)
	print('%.12f' % res)


import sys
import math
from collections import deque, Counter
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
mi = lambda : map(float, input().split())
li = lambda : list(mi())
mi1 = lambda : map(int1, input().split())
li1 = lambda : list(mi1())
mis = lambda : map(str, input().split())
lis = lambda : list(mis())
from collections import defaultdict
mod = 10 ** 9 + 7
Mod = 998244353
INF = 10 ** 18
ans = 0
mn = 10 ** (-6)

def f(c, m, p, v):
	cnt = 1
	if c <= v + mn:
		if c != 0:
			if m != 0:
				cnt += c * f(0, m + c / 2, p + c / 2, v)
			else:
				cnt += c
		else:
			pass
	elif m != 0:
		cnt += c * f(c - v, m + v / 2, p + v / 2, v)
	else:
		cnt += c * f(c - v, 0, p + v, v)
	if m <= v + mn:
		if m != 0:
			if c != 0:
				cnt += m * f(c + m / 2, 0, p + m / 2, v)
			else:
				cnt += m
	elif c != 0:
		cnt += m * f(c + v / 2, m - v, p + v / 2, v)
	else:
		cnt += m * f(0, m - v, p + v, v)
	return cnt
t = int(input())
for _ in range(t):
	(c, m, p, v) = mi()
	print(f(c, m, p, v))


t = int(input())
l = 1e-06

def solve(c, m, p, v, k=1, prob=1.0):
	s1 = 0
	s2 = 0
	if c > l:
		prev_prob = c * prob
		if c <= v:
			n_c = 0.0
			n_p = p + c
			n_m = 0.0
			if m > l:
				n_m = m + c / 2
				n_p = p + c / 2
			s1 = solve(n_c, n_m, n_p, v, k + 1, prev_prob)
		else:
			n_c = c - v
			n_p = p + v
			n_m = 0.0
			if m > l:
				n_m = m + v / 2
				n_p = p + v / 2
			s1 = solve(n_c, n_m, n_p, v, k + 1, prev_prob)
	if m > l:
		prev_prob = m * prob
		if m <= v:
			n_m = 0.0
			n_p = p + m
			n_c = 0.0
			if c > l:
				n_c = c + m / 2
				n_p = p + m / 2
			s2 = solve(n_c, n_m, n_p, v, k + 1, prev_prob)
		else:
			n_m = m - v
			n_p = p + v
			n_c = 0.0
			if c > l:
				n_c = c + v / 2
				n_p = p + v / 2
			s2 = solve(n_c, n_m, n_p, v, k + 1, prev_prob)
	return k * p * prob + s1 + s2
for _ in range(t):
	(c, m, p, v) = map(float, input().split())
	print(solve(c, m, p, v))


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
inf = 10 ** 4 * (1 << 10)
md = 10 ** 9 + 7
from collections import defaultdict
toint = lambda x: round(float(x) * inf)
for testcase in range(II()):
	(c, m, p, v) = map(toint, input().split())
	dp = defaultdict(float)
	dp[c, m, p] = 1
	ans = 0
	for k in range(1, 100):
		if not dp:
			break
		ndp = defaultdict(float)
		for ((c, m, p), r) in dp.items():
			if c > 0:
				if c < v:
					if m == 0:
						(nc, nm, np) = (0, 0, inf)
					else:
						(nc, nm, np) = (0, m + c // 2, p + c // 2)
				elif m == 0:
					(nc, nm, np) = (c - v, 0, p + v)
				else:
					(nc, nm, np) = (c - v, m + v // 2, p + v // 2)
				ndp[nc, nm, np] += r * c / inf
			if m > 0:
				if m < v:
					if c == 0:
						(nc, nm, np) = (0, 0, inf)
					else:
						(nc, nm, np) = (c + m // 2, 0, p + m // 2)
				elif c == 0:
					(nc, nm, np) = (0, m - v, p + v)
				else:
					(nc, nm, np) = (c + v // 2, m - v, p + v // 2)
				ndp[nc, nm, np] += r * m / inf
			ans += k * r * p / inf
			dp = ndp
	print(ans)


import sys
sys.setrecursionlimit(15000)
epsilon = 1e-05

def game(c, m, p, chosen, length=0):
	length += 1
	if chosen == 'p':
		return p * length
	if chosen == 'm':
		if m - v < epsilon:
			if c > epsilon:
				return m * game(c + m / 2, 0, p + m / 2, 'c', length) + m * game(c + m / 2, 0, p + m / 2, 'p', length)
			else:
				return m * game(c, 0, p + m, 'p', length)
		elif c > epsilon:
			return m * game(c + v / 2, m - v, p + v / 2, 'c', length) + m * game(c + v / 2, m - v, p + v / 2, 'm', length) + m * game(c + v / 2, m - v, p + v / 2, 'p', length)
		else:
			return m * game(c, m - v, p + v, 'm', length) + m * game(c, m - v, p + v, 'p', length)
	if chosen == 'c':
		if c - v < epsilon:
			if m > epsilon:
				return c * game(0, m + c / 2, p + c / 2, 'm', length) + c * game(0, m + c / 2, p + c / 2, 'p', length)
			else:
				return c * game(0, m, p + c, 'p', length)
		elif m > epsilon:
			return c * game(c - v, m + v / 2, p + v / 2, 'c', length) + c * game(c - v, m + v / 2, p + v / 2, 'm', length) + c * game(c - v, m + v / 2, p + v / 2, 'p', length)
		else:
			return c * game(c - v, m, p + v, 'c', length) + c * game(c - v, m, p + v, 'p', length)
t = int(input())
for _ in range(t):
	(c, m, p, v) = map(float, input().split())
	print(game(c, m, p, 'c') + game(c, m, p, 'm') + game(c, m, p, 'p'))


a = 0

def dp(c, m, p, v, h, ans):
	global a
	a += h * p * ans
	if c > 0 + 1e-09:
		if m < 1e-09:
			y = dp(c - min(c, v), m, p + min(c, v), v, h + 1, ans * c)
		else:
			y = dp(c - min(c, v), m + min(c, v) / 2, p + min(c, v) / 2, v, h + 1, ans * c)
	else:
		x2 = 1
	if m > 0 + 1e-09:
		if c < 1e-09:
			z = dp(c, m - min(m, v), p + min(m, v), v, h + 1, ans * m)
		else:
			z = dp(c + min(m, v) / 2, m - min(m, v), p + min(m, v) / 2, v, h + 1, ans * m)
for _ in range(int(input())):
	(c, m, p, v) = map(float, input().split())
	dp(c, m, p, v, 1.0, 1.0)
	print('%.12f' % round(a, 12))
	a = 0


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint
from itertools import permutations
from bisect import bisect_right
k = 10

def recur(a, b, c, v, cnt, p):
	if cnt > 1000:
		return 0
	ans = a / 10 ** k * cnt
	if b != 0:
		(na, nb, nc) = (0, 0, 0)
		db = 0
		if b > v:
			db = v
			nb = b - v
		else:
			db = b
			nb = 0
		if c != 0:
			ans += b / 10 ** k * recur(a + db / 2, nb, c + db / 2, v, cnt + 1, 1)
		else:
			ans += b / 10 ** k * recur(a + db, nb, c, v, cnt + 1, 1)
	if c != 0:
		(na, nb, nc) = (0, 0, 0)
		dc = 0
		if c > v:
			dc = v
			nc = c - v
		else:
			dc = c
			nc = 0
		if b != 0:
			ans += c / 10 ** k * recur(a + dc / 2, b + dc / 2, nc, v, cnt + 1, 1)
		else:
			ans += c / 10 ** k * recur(a + dc, b, nc, v, cnt + 1, 1)
	return ans

def main():
	(a, b, c, v) = map(float, input().split())
	a *= 10 ** k
	b *= 10 ** k
	c *= 10 ** k
	v *= 10 ** k
	print(recur(c, b, a, v, 1, 1))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


T = int(input())
for t in range(T):
	[c, m, p, v] = list(map(float, input().split()))

	def dp(c, m, p, k):
		if c < 1e-06:
			c = 0
		if m < 1e-06:
			m = 0
		a = min(c, v)
		b = min(m, v)
		if c == 0 and m == 0:
			return (k + 1) * p
		if m == 0:
			return c * dp(c - a, m, p + a, k + 1) + (k + 1) * p
		if c == 0:
			return m * dp(c, m - b, p + b, k + 1) + (k + 1) * p
		return c * dp(c - a, m + a / 2.0, p + a / 2.0, k + 1) + m * dp(c + b / 2.0, m - b, p + b / 2.0, k + 1) + (k + 1) * p
	print(dp(c, m, p, 0))


import sys
input = sys.stdin.readline

def calc(c, m, p, v):
	ANS = p / 10 ** 16
	if c != 0:
		M = min(c, v)
		if m == 0:
			ANS += c / 10 ** 16 * (1 + calc(c - M, 0, p + M, v))
		else:
			ANS += c / 10 ** 16 * (1 + calc(c - M, m + M // 2, p + M // 2, v))
	if m != 0:
		M = min(m, v)
		if c == 0:
			ANS += m / 10 ** 16 * (1 + calc(0, m - M, p + M, v))
		else:
			ANS += m / 10 ** 16 * (1 + calc(c + M // 2, m - M, p + M // 2, v))
	return ANS
t = int(input())
for tests in range(t):
	(c, m, p, v) = input().split()
	c += '0' * (10 - len(c))
	m += '0' * (10 - len(m))
	p += '0' * (10 - len(p))
	v += '0' * (10 - len(v))
	c = int(c[2:]) * 10 ** 8
	m = int(m[2:]) * 10 ** 8
	p = int(p[2:]) * 10 ** 8
	v = int(v[2:]) * 10 ** 8
	print(calc(c, m, p, v))


import os, sys
from io import BytesIO, IOBase
from collections import deque

def main():
	eps = 10 ** (-9)
	for _ in range(int(input())):
		(c, m, p, v) = map(float, input().split())
		z = v / 2
		curr = deque([(c, m, p)])
		moves = deque([0])
		prob = deque([1.0])
		ans = 0.0
		while len(curr):
			(x, mo, pr) = (curr.popleft(), moves.popleft(), prob.popleft())
			ans += pr * x[2] * (mo + 1)
			if x[0] >= v:
				if x[1] > eps:
					curr.append((x[0] - v, x[1] + z, x[2] + z))
				else:
					curr.append((x[0] - v, x[1], x[2] + v))
				moves.append(mo + 1)
				prob.append(pr * x[0])
			elif x[0] > eps:
				if x[1] > eps:
					curr.append((0, x[1] + x[0] / 2, x[2] + x[0] / 2))
				else:
					curr.append((0, 0, 1))
				moves.append(mo + 1)
				prob.append(pr * x[0])
			if x[1] >= v:
				if x[0] > eps:
					curr.append((x[0] + z, x[1] - v, x[2] + z))
				else:
					curr.append((x[0], x[1] - v, x[2] + v))
				moves.append(mo + 1)
				prob.append(pr * x[1])
			elif x[1] > eps:
				if x[0] > eps:
					curr.append((x[0] + x[1] / 2, 0, x[2] + x[1] / 2))
				else:
					curr.append((0, 0, 1))
				moves.append(mo + 1)
				prob.append(pr * x[1])
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def getnext(c, m, p, v, dic):
	digit = 6
	if abs(c + m + p - 1) > 1e-07:
		print('ERROR', c, m, p)
	if (c, m, p) in dic:
		return dic[c, m, p]
	sit1 = 0
	sit2 = 0
	if c >= v:
		if m > 0:
			sit1 = getnext(round(c - v, digit), round(m + 0.5 * v, digit), round(p + 0.5 * v, digit), v, dic) + 1
		else:
			sit1 = getnext(round(c - v, digit), m, round(p + v, digit), v, dic) + 1
	elif c > 0:
		if m > 0:
			sit1 = getnext(0, round(m + 0.5 * c, digit), round(p + 0.5 * c, digit), v, dic) + 1
		else:
			sit1 = getnext(0, 0, 1, v, dic) + 1
	if m >= v:
		if c > 0:
			sit2 = getnext(round(c + 0.5 * v, digit), round(m - v, digit), round(p + 0.5 * v, digit), v, dic) + 1
		else:
			sit2 = getnext(c, round(m - v, digit), round(p + v, digit), v, dic) + 1
	elif m > 0:
		if c > 0:
			sit2 = getnext(round(c + 0.5 * m, digit), 0, round(p + 0.5 * m, digit), v, dic) + 1
		else:
			sit2 = getnext(0, 0, 1, v, dic) + 1
	sit3 = 1
	output = round(c * sit1 + m * sit2 + p * sit3, 12)
	dic[c, m, p] = output
	return output
T = int(input())
t = 1
while t <= T:
	(c, m, p, v) = map(float, input().split())
	dic = {}
	ans = getnext(c, m, p, v, dic)
	print(ans)
	t += 1


def solve(c, m, p, v, cnt):
	if 1 - p < 1e-05:
		return cnt
	ret = 0
	if c >= 1e-05 and m >= 1e-05:
		if c <= v:
			ret += c * solve(0, m + c / 2, p + c / 2, v, cnt + 1)
		else:
			ret += c * solve(c - v, m + v / 2, p + v / 2, v, cnt + 1)
		if m <= v:
			ret += m * solve(c + m / 2, 0, p + m / 2, v, cnt + 1)
		else:
			ret += m * solve(c + v / 2, m - v, p + v / 2, v, cnt + 1)
	elif c < 1e-05:
		if m <= v:
			ret += m * solve(0, 0, 1, v, cnt + 1)
		else:
			ret += m * solve(0, m - v, p + v, v, cnt + 1)
	elif m < 1e-05:
		if c <= v:
			ret += c * solve(0, 0, 1, v, cnt + 1)
		else:
			ret += c * solve(c - v, 0, p + v, v, cnt + 1)
	ret += p * cnt
	return ret
for _ in range(int(input())):
	(qc, qm, qp, qv) = map(float, input().split())
	print(solve(qc, qm, qp, qv, 1))


def dfs(c, m, p, v, steps, prob):
	ans = 0
	if c != -1:
		if m != -1:
			if c <= v:
				ans += dfs(-1, m + c / 2, p + c / 2, v, steps + 1, prob * c / r)
			else:
				ans += dfs(c - v, m + v / 2, p + v / 2, v, steps + 1, prob * c / r)
		elif c <= v:
			ans += dfs(-1, -1, p + c, v, steps + 1, prob * c / r)
		else:
			ans += dfs(c - v, -1, p + v, v, steps + 1, prob * c / r)
	if m != -1:
		if c != -1:
			if m <= v:
				ans += dfs(c + m / 2, -1, p + m / 2, v, steps + 1, prob * m / r)
			else:
				ans += dfs(c + v / 2, m - v, p + v / 2, v, steps + 1, prob * m / r)
		elif m <= v:
			ans += dfs(-1, -1, p + m, v, steps + 1, prob * m / r)
		else:
			ans += dfs(-1, m - v, p + v, v, steps + 1, prob * m / r)
	if p:
		ans += steps * prob * p / r
	return ans
r = 10 ** 9
T = int(input())
for case in range(T):
	(c, m, p, v) = list(map(float, input().split()))
	c *= r
	m *= r
	p *= r
	v *= r
	answer = dfs(c, m, p, v, 1, 1)
	print(answer)


scale = 10 ** 6

def backtrack(c, m, p, v):
	ans = p / scale
	if c > 0:
		if c > v:
			ans += c / scale * (1 + backtrack(c - v, m + v / 2, p + v / 2, v)) if m else c / scale * (1 + backtrack(c - v, 0, p + v, v))
		else:
			ans += c / scale * (1 + backtrack(0, m + c / 2, p + c / 2, v)) if m else c / scale * (1 + backtrack(0, 0, p + c, v))
	if m > 0:
		if m > v:
			ans += m / scale * (1 + backtrack(c + v / 2, m - v, p + v / 2, v)) if c else m / scale * (1 + backtrack(0, m - v, p + v, v))
		else:
			ans += m / scale * (1 + backtrack(c + m / 2, 0, p + m / 2, v)) if c else m / scale * (1 + backtrack(0, 0, p + m, v))
	return ans
t = int(input())
for _ in range(t):
	inp = input().split()
	(c, m, p, v) = (float(inp[0]), float(inp[1]), float(inp[2]), float(inp[3]))
	print(backtrack(round(c * scale), round(m * scale), round(p * scale), round(v * scale)))


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1

def dfs(a, b, p, c):
	if a == b:
		return c
	for (i, j) in adj[a]:
		if i == p:
			continue
		temp = dfs(i, b, a, c + j)
		if dfs(i, b, a):
			mx = max(i, mx)
			return 1
eps = 9e-07

def dfs1(c, m, p, v, prob, steps):
	ans = steps * prob * p
	if c > eps:
		dist = min(v, c)
		p1 = p
		m1 = m
		if m > eps:
			p1 += dist / 2
			m1 += dist / 2
		else:
			p1 += dist
			m1 = 0
		c1 = c - dist
		ans += dfs1(c1, m1, p1, v, prob * c, steps + 1)
	if m > eps:
		dist = min(v, m)
		p1 = p
		c1 = c
		if c > eps:
			p1 += dist / 2
			c1 += dist / 2
		else:
			p1 += dist
			c1 = 0
		m1 = m - dist
		ans += dfs1(c1, m1, p1, v, prob * m, steps + 1)
	return ans

def hnbhai(tc):
	(c, m, p, v) = sflo()
	print(dfs1(c, m, p, v, 1, 1))

def dfs(root):
	global tot, vis, gp
	for child in gp[root]:
		if vis[child] == 0:
			tot += 1
			vis[child] = 1
			dfs(child)
for _ in range(sb()):
	flsh()
	hnbhai(_ + 1)


t = int(input())
for _ in range(t):
	(c, m, p, v) = map(float, input().split())

	def dp(c, m, p):
		ans = 1
		if c > 1e-06:
			ch = min(c, v)
			nc = c - ch
			nm = m + ch / 2
			np = p + ch / 2
			if m < 1e-06:
				nm = m
				np += ch / 2
			ans += c * dp(nc, nm, np)
		if m > 1e-06:
			ch = min(m, v)
			nm = m - ch
			nc = c + ch / 2
			np = p + ch / 2
			if c < 1e-06:
				nc = c
				np += ch / 2
			ans += m * dp(nc, nm, np)
		return ans
	print(dp(c, m, p))


import sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
tc = 1
tc = int(input())
for test in range(1, tc + 1):
	(c, m, p, v) = map(float, input().split())
	error = 10 ** (-8)

	def solve(c, m, p, g):
		if c <= error:
			c = 0
		if m <= error:
			m = 0
		ans = 0
		if c != 0:
			if c <= v:
				if m == 0:
					ans += c * solve(0, 0, p + c, g + 1)
				else:
					ans += c * solve(0, m + c / 2, p + c / 2, g + 1)
			elif m == 0:
				ans += c * solve(c - v, 0, p + v, g + 1)
			else:
				ans += c * solve(c - v, m + v / 2, p + v / 2, g + 1)
		if m != 0:
			if c == 0:
				if m <= v:
					ans += m * solve(0, 0, p + m, g + 1)
				else:
					ans += m * solve(0, m - v, p + v, g + 1)
			elif m <= v:
				ans += m * solve(c + m / 2, 0, p + m / 2, g + 1)
			else:
				ans += m * solve(c + v / 2, m - v, p + v / 2, g + 1)
		ans += p * g
		return ans
	ans = solve(c, m, p, 1)
	print(ans)


from decimal import *

def solve(c1, m1, p, v, n):
	c = 0
	m = 0
	if c1 > m1:
		c = m1
		m = c1
	else:
		c = c1
		m = m1
	ans = n * p
	if c == 0:
		if m != 0:
			if v >= m:
				ans += (1 - p) * solve(0, 0, 1, v, n + 1)
			else:
				ans += (1 - p) * solve(0, m - v, p + v, v, n + 1)
	elif v <= c:
		ans += c * solve(c - v, m + v / 2, p + v / 2, v, n + 1)
		ans += m * solve(c + v / 2, m - v, p + v / 2, v, n + 1)
	elif v > m:
		ans += c * solve(0, m + c / 2, p + c / 2, v, n + 1)
		ans += m * solve(c + m / 2, 0, p + m / 2, v, n + 1)
	else:
		ans += c * solve(0, m + c / 2, p + c / 2, v, n + 1)
		ans += m * solve(c + v / 2, m - v, p + v / 2, v, n + 1)
	return ans
t = int(input())
while t > 0:
	a = input().split(' ')
	(c, m, p, v) = (Decimal(a[0]), Decimal(a[1]), Decimal(a[2]), Decimal(a[3]))
	print(solve(c, m, p, v, 1))
	t -= 1


from decimal import *
getcontext().prec = 20

def dfs(c, m, v):
	ans = Decimal(1)
	if c > 0:
		if c <= v:
			if m > 0:
				ans += c * dfs(0, m + c / 2, v)
			else:
				ans += c * dfs(0, 0, v)
		elif m > 0:
			ans += c * dfs(c - v, m + v / 2, v)
		else:
			ans += c * dfs(c - v, 0, v)
	if m > 0:
		if m <= v:
			if c > 0:
				ans += m * dfs(c + m / 2, 0, v)
			else:
				ans += m * dfs(0, 0, v)
		elif c > 0:
			ans += m * dfs(c + v / 2, m - v, v)
		else:
			ans += m * dfs(0, m - v, v)
	return ans
t = int(input())
for i in range(t):
	(c, m, p, v) = map(Decimal, input().split())
	print(dfs(c, m, v))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
	(c, m, p, v) = map(float, input().split())
	eps = 10 ** (-9)

	def dfs(cnt, x, c, m, p):
		cnt += 1
		ret = 0
		ret = x * p * cnt
		if c != 0:
			if c < v + eps:
				if m == 0:
					ret += dfs(cnt, x * c, 0, 0, 1)
				else:
					ret += dfs(cnt, x * c, 0, m + c / 2, p + c / 2)
			elif m == 0:
				ret += dfs(cnt, x * c, c - v, 0, p + v)
			else:
				ret += dfs(cnt, x * c, c - v, m + v / 2, p + v / 2)
		if m != 0:
			if m < v + eps:
				if c == 0:
					ret += dfs(cnt, x * m, 0, 0, 1)
				else:
					ret += dfs(cnt, x * m, c + m / 2, 0, p + m / 2)
			elif c == 0:
				ret += dfs(cnt, x * m, 0, m - v, p + v)
			else:
				ret += dfs(cnt, x * m, c + v / 2, m - v, p + v / 2)
		return ret
	print(dfs(0, 1, c, m, p))
for _ in range(int(input())):
	main()


prob = 0
v = 0

def rec(c, m, p, val, num):
	global prob
	global v
	prob += val * p * num
	if p < 0.999994:
		if c > 1e-06:
			if c > v:
				if m > 1e-06:
					rec(c - v, m + v / 2, p + v / 2, val * c, num + 1)
				else:
					rec(c - v, 0, p + v, val * c, num + 1)
			elif m > 1e-06:
				rec(0, m + c / 2, p + c / 2, val * c, num + 1)
			else:
				rec(0, 0, p + c, val * c, num + 1)
		if m > 1e-06:
			if m > v:
				if c > 1e-06:
					rec(c + v / 2, m - v, p + v / 2, val * m, num + 1)
				else:
					rec(0, m - v, p + v, val * m, num + 1)
			elif c > 1e-06:
				rec(c + m / 2, 0, p + m / 2, val * m, num + 1)
			else:
				rec(0, 0, p + m, val * m, num + 1)
for t in range(int(input())):
	prob = 0
	(c, m, p, v) = map(float, input().split())
	rec(c, m, p, 1, 1)
	print(prob)


ans = 0
import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())

def fun(c, m, p, v, itr, acc):
	global ans
	if c < 10 ** (-6) and m < 10 ** (-6):
		ans += itr * acc
		return
	if c > 10 ** (-6):
		bc = c
		tmp = min(c, v)
		bc -= tmp
		if m > 10 ** (-6):
			fun(bc, m + tmp / 2, p + tmp / 2, v, itr + 1, acc * c)
		else:
			fun(bc, m, p + tmp, v, itr + 1, acc * c)
	if m > 10 ** (-6):
		bm = m
		tmp = min(m, v)
		bm -= tmp
		if c > 10 ** (-6):
			fun(c + tmp / 2, bm, p + tmp / 2, v, itr + 1, acc * m)
		else:
			fun(c, bm, p + tmp, v, itr + 1, acc * m)
	ans += acc * itr * p
for _ in range(t):
	(c, m, p, v) = list(map(float, stdin.readline().rstrip().split()))
	ans = 0
	fun(c, m, p, v, 1, 1)
	print(ans)


from decimal import Decimal

def f(c, m, p, v, q, o):
	if c > 0:
		d = min(c, v)
		if abs(c - d) < 1e-10:
			d = c
		o.append(q * c)
		if m > 0:
			f(c - d, m + d / 2, p + d / 2, v, q * c, o)
		else:
			f(c - d, 0, p + d, v, q * c, o)
	if m > 0:
		d = min(m, v)
		if abs(m - d) < 1e-10:
			d = m
		o.append(q * m)
		if c > 0:
			f(c + d / 2, m - d, p + d / 2, v, q * m, o)
		else:
			f(0, m - d, p + d, v, q * m, o)
	o.append(q * p)

def g(c, m, p, v):
	o = []
	f(c, m, p, v, 1, o)
	return sum(sorted(o))
for _ in range(int(input())):
	print(g(*map(float, input().split())))


import sys
from sys import stdout
sys.setrecursionlimit(10000)
input = lambda : sys.stdin.readline().strip()
P = lambda : list(map(int, input().split()))
from math import factorial as f, gcd
from collections import deque, defaultdict as dd, Counter as C
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge
from random import randint, choice, sample
from functools import lru_cache
import time
mod = 10 ** 9 + 7
a = ord('a')
start = time.time()

def fast_exp(x, exp):
	ans = 1
	base = x
	while exp:
		if exp & 1:
			ans *= base
		base *= base
		base %= mod
		ans %= mod
		exp >>= 1
	return ans

def countBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count

def submasks(n):
	org = n
	while n:
		yield n
		n = n - 1 & org

def solve():
	(c, m, p, v) = map(float, input().split())
	count = 0

	@lru_cache(maxsize=None)
	def val(c, m, p):
		nonlocal count
		count += 1
		ans = 0
		if c:
			diff = c if c <= v else v
			if m:
				ans += c * (1 + val(round(c - diff, 9), round(m + diff / 2, 9), round(p + diff / 2, 9)))
			else:
				ans += c * (1 + val(round(c - diff, 9), 0, round(p + diff, 9)))
		if m:
			diff = m if m <= v else v
			if c:
				ans += m * (1 + val(round(c + diff / 2, 9), round(m - diff, 9), round(p + diff / 2, 9)))
			else:
				ans += m * (1 + val(0, round(m - diff, 9), round(p + diff, 9)))
		ans += p
		return ans
	print(val(c, m, p))
tc = int(input())
for t in range(1, tc + 1):
	solve()


from collections import Counter, deque, defaultdict
from heapq import *
from decimal import *
import sys
sys.setrecursionlimit(1000000)

def inp():
	return int(input())

def mapInput():
	return map(Decimal, input().split())

def arrInput():
	return list(map(Decimal, input().split()))
div = Decimal(2)

def rounds(c, m, p, v):
	if c == 0 and m == 0:
		return 1
	res = 1
	if c > 0:
		(x, y, z) = (c, m, p)
		reduced = -1
		if x > v:
			reduced = v / 2
			x -= v
		else:
			reduced = x / 2
			x = 0
		z += reduced
		if y > 0:
			y += reduced
		else:
			z += reduced
		res += c * rounds(x, y, z, v)
	if m > 0:
		(x, y, z) = (c, m, p)
		reduced = -1
		if y > v:
			reduced = v / div
			y -= v
		else:
			reduced = y / div
			y = 0
		z += reduced
		if x > 0:
			x += reduced
		else:
			z += reduced
		res += m * rounds(x, y, z, v)
	return res

def task():
	(c, m, p, v) = mapInput()
	print(rounds(c, m, p, v))
for _ in range(inp()):
	task()


from decimal import *

def numMoves(c, m, p, v):
	ans = 1
	if c != -1:
		if c <= v:
			if m != -1:
				ans += c * numMoves(-1, m + c / 2, p + c / 2, v)
			else:
				ans += c * numMoves(-1, m, p + c, v)
		elif m != -1:
			ans += c * numMoves(c - v, m + v / 2, p + v / 2, v)
		else:
			ans += c * numMoves(c - v, m, p + v, v)
	if m != -1:
		if m <= v:
			if c != -1:
				ans += m * numMoves(c + m / 2, -1, p + m / 2, v)
			else:
				ans += m * numMoves(c, -1, p + m, v)
		elif c != -1:
			ans += m * numMoves(c + v / 2, m - v, p + v / 2, v)
		else:
			ans += m * numMoves(c, m - v, p + v, v)
	return ans
for _ in range(int(input())):
	lst = input().split()
	c = Decimal(lst[0])
	m = Decimal(lst[1])
	p = Decimal(lst[2])
	v = Decimal(lst[3])
	print(numMoves(c, m, p, v))


from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
scale = 10 ** 6

def rec(c, m, p, v):
	res = p / scale
	if c > 0:
		if c > v:
			if m > 0:
				res += c / scale * (1 + rec(c - v, m + v / 2, p + v / 2, v))
			else:
				res += c / scale * (1 + rec(c - v, 0, p + v, v))
		elif m > 0:
			res += c / scale * (1 + rec(0, m + c / 2, p + c / 2, v))
		else:
			res += c / scale * (1 + rec(0, 0, p + c, v))
	if m > 0:
		if m > v:
			if c > 0:
				res += m / scale * (1 + rec(c + v / 2, m - v, p + v / 2, v))
			else:
				res += m / scale * (1 + rec(0, m - v, p + v, v))
		elif c > 0:
			res += m / scale * (1 + rec(c + m / 2, 0, p + m / 2, v))
		else:
			res += m / scale * (1 + rec(0, 0, p + m, v))
	return res
t = int(input())
for i in range(t):
	(cm, mm, pm, vv) = [float(i) for i in input().split()]
	print(rec(cm * scale, mm * scale, pm * scale, vv * scale))


def solve(c, m, p, v):
	exp_tot = 0
	prob = 1
	if c == 0 and m == 0:
		return exp_tot
	stack = [(c, m, p, v, prob, 0, '')]
	while len(stack) != 0:
		(c, m, p, v, prob, round, slips) = stack.pop()
		exp_tot += (round + 1) * (prob * p)
		if c > 10 ** (-8):
			(c_new, m_new, p_new) = get_new_cmp(c, m, p, v)
			stack.append((c_new, m_new, p_new, v, prob * c, round + 1, slips + 'C'))
		if m > 10 ** (-8):
			(m_new, c_new, p_new) = get_new_cmp(m, c, p, v)
			stack.append((c_new, m_new, p_new, v, prob * m, round + 1, slips + 'M'))
	return exp_tot

def get_new_cmp(c, m, p, v):
	if c <= v:
		c_new = 0
		if m < 10 ** (-8):
			p_new = 1
			m_new = 0
		else:
			m_new = m + c / 2
			p_new = p + c / 2
	else:
		c_new = max(0, c - v)
		if m < 10 ** (-8):
			p_new = p + v
			m_new = 0
		else:
			m_new = m + v / 2
			p_new = p + v / 2
	return (c_new, m_new, p_new)
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input().decode().strip())
for t in range(T):
	(c, m, p, v) = [float(x) for x in input().decode().strip().split(' ')]
	res = solve(c, m, p, v)
	print(res)


from math import *
dic = {}

def brt(lst):
	if tuple(lst) in dic:
		return dic[tuple(lst)]
	prob1 = lst[0] / (lst[0] + lst[1] + lst[2])
	prob2 = lst[1] / (lst[0] + lst[1] + lst[2])
	prob3 = lst[2] / (lst[0] + lst[1] + lst[2])
	val = prob3
	if lst[0] > 0:
		nxt1 = list(lst)
		dff = min(v, nxt1[0])
		nxt1[0] -= v
		if nxt1[0] < 0:
			nxt1[0] = 0
		ctt = 1 + (nxt1[1] > 0)
		nxt1[2] += dff / ctt
		if nxt1[1] > 0:
			nxt1[1] += dff / ctt
		if prob1 > 0:
			val = val + prob1 * (1 + brt(nxt1))
	if lst[1] > 0:
		nxt2 = list(lst)
		dff = min(v, nxt2[1])
		nxt2[1] -= v
		if nxt2[1] < 0:
			nxt2[1] = 0
		ctt = 1 + (nxt2[0] > 0)
		nxt2[2] += dff / ctt
		if nxt2[0] > 0:
			nxt2[0] += dff / ctt
		if prob2 > 0:
			val = val + prob2 * (1 + brt(nxt2))
	dic[tuple(lst)] = val
	return val
n = int(input())
for i in range(n):
	dic.clear()
	(sc, sm, sp, sv) = input().split(' ')
	c = float(sc) * 10000
	m = float(sm) * 10000
	p = float(sp) * 10000
	v = float(sv) * 10000
	print(brt([c, m, p]))


def f(c, m, p, v):
	if abs(1 - p) < 10 ** (-7):
		return 1
	if c < 10 ** (-7):
		ans = 0
		if m - v > 0:
			ans += m * (f(0, m - v, p + v, v) + 1)
		else:
			ans += m * 2
		ans += p
		return ans
	elif m < 10 ** (-7):
		ans = 0
		if c > v:
			ans += c * (f(c - v, 0, p + v, v) + 1)
		else:
			ans += c * 2
		ans += p
		return ans
	else:
		ans = 0
		if c - v > 0:
			ans += c * (f(c - v, m + v / 2, p + v / 2, v) + 1)
		else:
			ans += c * (f(0, m + c / 2, p + c / 2, v) + 1)
		if m - v > 0:
			ans += m * (f(c + v / 2, m - v, p + v / 2, v) + 1)
		else:
			ans += m * (f(c + m / 2, 0, p + m / 2, v) + 1)
		ans += p
		return ans
for __ in range(int(input())):
	(c, m, p, v) = map(float, input().split())
	print(f(c, m, p, v))


ans = []
eps = 1e-06
for _ in range(int(input())):
	(c, m, p, v) = map(float, input().split())
	cur = p
	pr = [(1, c, m, p)]
	st = 1
	while len(pr) > 0:
		st += 1
		pr1 = []
		for i in range(len(pr)):
			(cur_pr, c, m, p) = pr[i]
			if c > eps:
				if c > v:
					if m > eps:
						(c1, m1, p1) = (c - v, m + v / 2, p + v / 2)
					else:
						(c1, m1, p1) = (c - v, 0, p + v)
				elif m > eps:
					(c1, m1, p1) = (0, m + c / 2, p + c / 2)
				else:
					(c1, m1, p1) = (0, 0, p + c)
				cur_pr1 = cur_pr * c
				cur += st * cur_pr1 * p1
				if abs(p1 - 1) > eps:
					pr1.append((cur_pr1, c1, m1, p1))
			if m > eps:
				if m > v:
					if c > eps:
						(c1, m1, p1) = (c + v / 2, m - v, p + v / 2)
					else:
						(c1, m1, p1) = (0, m - v, p + v)
				elif c > eps:
					(c1, m1, p1) = (c + m / 2, 0, p + m / 2)
				else:
					(c1, m1, p1) = (0, 0, p + m)
				cur_pr1 = cur_pr * m
				cur += st * cur_pr1 * p1
				if abs(p1 - 1) > eps:
					pr1.append((cur_pr1, c1, m1, p1))
		pr = pr1[:]
	ans.append(cur)
print('\n'.join(map(str, ans)))


def dfs(c, m, p, n, k):
	global v, res
	res += p * n * k
	if c > 1e-06 and m > 1e-06:
		if c >= v:
			dfs(c - v, m + v / 2, p + v / 2, n * c, k + 1)
		else:
			dfs(0, m + c / 2, p + c / 2, n * c, k + 1)
		if m >= v:
			dfs(c + v / 2, m - v, p + v / 2, n * m, k + 1)
		else:
			dfs(c + m / 2, 0, p + m / 2, n * m, k + 1)
	elif c > 1e-06:
		if c >= v:
			dfs(c - v, m, p + v, n * c, k + 1)
		else:
			dfs(0, 0, p + c, n * c, k + 1)
	elif m > 1e-06:
		if m >= v:
			dfs(c, m - v, p + v, n * m, k + 1)
		else:
			dfs(0, 0, p + m, n * m, k + 1)
for _ in range(int(input())):
	(c, m, p, v) = map(float, input().split())
	res = 0
	dfs(c, m, p, 1, 1)
	print(res)


from decimal import Decimal
from decimal import *
v = 1

def f(a, b, l):
	t1 = 1
	t2 = 1
	t3 = 1
	if a == 0 and b == 0:
		return l * t3
	if a == 0:
		if b <= v:
			return l * (t3 - b) + (l + 1) * b
		else:
			return b * f(0, b - v, l + 1) + l * (t3 - b)
	if b == 0:
		if a <= v:
			return l * (t3 - a) + (l + 1) * a
		else:
			return a * f(0, a - v, l + 1) + l * (t3 - a)
	if a <= v:
		t1 = f(0, b + a / 2, l + 1)
	else:
		t1 = f(a - v, b + v / 2, l + 1)
	if b <= v:
		t2 = f(a + b / 2, 0, l + 1)
	else:
		t2 = f(a + v / 2, b - v, l + 1)
	return l * (t3 - a - b) + a * t1 + b * t2
T = int(input())
for i in range(0, T):
	(a, b, c, v) = map(Decimal, input().split())
	print(f(a, b, 1))


from decimal import *

def f(a, b, v):
	ans = 1
	if a <= v:
		ans += a
	else:
		ans += a * f(a - v, b + v, v)
	return ans

def g(a, b, c, v):
	ans = 1
	if a <= v:
		ans += a * f(b + a / 2, c + a / 2, v)
	else:
		ans += a * g(a - v, b + v / 2, c + v / 2, v)
	if b <= v:
		ans += b * f(a + b / 2, c + b / 2, v)
	else:
		ans += b * g(a + v / 2, b - v, c + v / 2, v)
	return ans

def main():
	t = int(input())
	for i in range(t):
		ans = g(*map(Decimal, input().split()))
		print(f'{ans:.12f}')
main()


def E(c, m, p, v):
	ans = 0
	if p > 1e-06:
		ans += p
	if c > 1e-06:
		m2 = m
		p2 = p
		if m > 1e-06 and p > 1e-06:
			m2 += min(c, v) / 2
			p2 += min(c, v) / 2
		elif p > 1e-06:
			p2 += min(c, v)
		ans += c * (1 + E(max(c - v, 0), m2, p2, v))
	if m > 1e-06:
		c1 = c
		p1 = p
		if c > 1e-06 and p > 1e-06:
			c1 += min(m, v) / 2
			p1 += min(m, v) / 2
		elif p > 1e-06:
			p1 += min(m, v)
		ans += m * (1 + E(c1, max(m - v, 0), p1, v))
	return ans
for _ in range(int(input())):
	(c, m, p, v) = list(map(float, input().split()))
	print(E(c, m, p, v))


zero = 1e-06

def f(c, m, p, v, i, prob):
	if 1 - p <= zero:
		return 0
	a1 = 0
	c1 = c
	m1 = m
	p1 = p
	prob1 = prob
	if c > zero:
		o = min(c, v)
		if m > zero:
			(m, p) = (m + o / 2, p + o / 2)
		else:
			p = p + o
		prob = prob * c
		a1 = i * prob * p + f(c - o, m, p, v, i + 1, prob)
	a2 = 0
	if m > zero:
		t = min(m1, v)
		if c1 > zero:
			(c1, p1) = (c1 + t / 2, p1 + t / 2)
		else:
			p1 = p1 + t
		prob1 = prob1 * m1
		a2 = i * prob1 * p1 + f(c1, m1 - t, p1, v, i + 1, prob1)
	return a1 + a2
for _ in range(int(input())):
	(c, m, p, v) = map(float, input().split())
	print(f(c, m, p, v, 2, 1) + p)


def naiveSolve():
	return

def changeA(a, a2, b, c):
	if abs(b) < 1e-05:
		return (0, 1 - a2)
	d = (a - a2) / 2
	return (b + d, c + d)

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(c, m, p, v) = readFloatArr()

		def E(c, m, p):
			res = 1 * p
			if c > 0:
				newC = max(0, c - v)
				(newM, newP) = changeA(c, newC, m, p)
				res += c * (1 + E(newC, newM, newP))
			if m > 0:
				newM = max(0, m - v)
				(newC, newP) = changeA(m, newM, c, p)
				res += m * (1 + E(newC, newM, newP))
			return res
		ans = E(c, m, p)
		allans.append(ans)
	multiLineArrayPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def readFloatArr():
	return [float(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x):
	print('{}'.format(x))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
from math import gcd, floor, ceil
for _abc in range(1):
	main()


from decimal import Decimal as D
SCALE = 1000000.0

def find_odds(c: float, m: float, p: float, v: float, cumulative: float=SCALE, depth=1) -> float:
	total = cumulative / SCALE * p / SCALE * depth
	if c > 0:
		new_c = max(0.0, c - v)
		delta = c - new_c
		if m > 0:
			new_p = p + 0.5 * delta
			new_m = m + 0.5 * delta
		else:
			new_p = p + delta
			new_m = 0
		total += find_odds(new_c, new_m, new_p, v, cumulative * c / SCALE, depth + 1)
	if m > 0:
		new_m = max(0.0, m - v)
		delta = m - new_m
		if c > 0:
			new_p = p + 0.5 * delta
			new_c = c + 0.5 * delta
		else:
			new_p = p + delta
			new_c = 0
		total += find_odds(new_c, new_m, new_p, v, cumulative * m / SCALE, depth + 1)
	return total
DECIMAL_ZERO = D(0)
DECIMAL_HALF = D(0.5)
DECIMAL_ONE = D(1)

def find_odds_decimal(c: D, m: D, p: D, v: D, cumulative: D=DECIMAL_ONE, depth: int=1) -> D:
	total = cumulative * p * depth
	if c > 0:
		new_c = max(DECIMAL_ZERO, c - v)
		delta = c - new_c
		if m > 0:
			new_p = p + DECIMAL_HALF * delta
			new_m = m + DECIMAL_HALF * delta
		else:
			new_p = p + delta
			new_m = 0
		total += find_odds_decimal(new_c, new_m, new_p, v, cumulative * c, depth + 1)
	if m > 0:
		new_m = max(DECIMAL_ZERO, m - v)
		delta = m - new_m
		if c > 0:
			new_p = p + DECIMAL_HALF * delta
			new_c = c + DECIMAL_HALF * delta
		else:
			new_p = p + delta
			new_c = 0
		total += find_odds_decimal(new_c, new_m, new_p, v, cumulative * m, depth + 1)
	return total
for _ in range(int(input())):
	(c, m, p, v) = [float(i) for i in input().split(' ')]
	print(find_odds(c * SCALE, m * SCALE, p * SCALE, v * SCALE))


import random
import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mo = int(1000000000.0 + 7)

def exgcd(a, b):
	if not b:
		return (1, 0)
	(y, x) = exgcd(b, a % b)
	y -= a // b * x
	return (x, y)

def getinv(a, m):
	(x, y) = exgcd(a, m)
	return -1 if x == 1 else x % m

def comb(n, b):
	res = 1
	b = min(b, n - b)
	for i in range(b):
		res = res * (n - i) * getinv(i + 1, mo) % mo
	return res % mo

def quickpower(a, n):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def quickpowerm(a, n, mo):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])

def getpref(x):
	if x > 1:
		return x * (x - 1) >> 1
	else:
		return 0

def orafli(upp):
	primes = []
	marked = [False for i in range(upp + 3)]
	prvs = [i for i in range(upp + 3)]
	for i in range(2, upp):
		if not marked[i]:
			primes.append(i)
		for j in primes:
			if i * j >= upp:
				break
			marked[i * j] = True
			prvs[i * j] = j
			if i % j == 0:
				break
	return (primes, prvs)

def lower_ord(c: str) -> int:
	return ord(c) - 97

def upper_ord(c: str) -> int:
	return ord(c) - 65

def read_list():
	return [int(i) for i in input().split()]

def read_int():
	s = input().split()
	if len(s) == 1:
		return int(s[0])
	else:
		return map(int, s)

def ask(s):
	print(f'? {s}', flush=True)

def answer(s):
	print(f'{s}', flush=True)
import functools
import itertools
from fractions import Fraction

def solve():
	cache = {}
	(c, m, p, v) = [float(i) for i in input().split()]
	v2 = v / 2

	def dfs(cc, mm, pp, dep) -> float:
		res = pp * dep
		if cc > 1e-10:
			if cc > v:
				if mm < 1e-10:
					res += cc * dfs(cc - v, 0, pp + v, dep + 1)
				else:
					res += cc * dfs(cc - v, mm + v2, pp + v2, dep + 1)
			elif mm < 1e-10:
				res += cc * dfs(0, 0, 1, dep + 1)
			else:
				res += cc * dfs(0, mm + cc / 2, pp + cc / 2, dep + 1)
		if mm > 1e-10:
			if mm > v:
				if cc < 1e-10:
					res += mm * dfs(0, mm - v, pp + v, dep + 1)
				else:
					res += mm * dfs(cc + v2, mm - v, pp + v2, dep + 1)
			elif cc < 1e-10:
				res += mm * dfs(0, 0, 1, dep + 1)
			else:
				res += mm * dfs(cc + mm / 2, 0, pp + mm / 2, dep + 1)
		return res
	rr = dfs(c, m, p, 1)
	print(rr)
T = int(input())
for ti in range(T):
	solve()


import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 4)
EPS = 1e-05
for _ in range(int(input())):
	(C, M, P, V) = map(float, input().split())

	def f(a: float, b: float, depth: int) -> float:
		if depth == 22:
			return 0.0
		v = 1.0 - a - b
		res = depth * v
		if a > EPS:
			take = min(a, V)
			nb = b + take / 2 if b > EPS else b
			res += a * f(a - take, nb, depth + 1)
		if b > EPS:
			take = min(b, V)
			na = a + take / 2 if a > EPS else a
			res += b * f(na, b - take, depth + 1)
		return res
	print(f(C, M, 1))


import sys
from itertools import zip_longest
EPS = 1e-08

def read_floats():
	return [float(i) for i in sys.stdin.readline().strip().split()]

def read_int():
	return int(sys.stdin.readline().strip())

def probs(c, m, p, v):
	if c > m:
		return probs(m, c, p, v)
	if c < EPS:
		if v >= m:
			return [p, 1 - p]
		else:
			return [p] + [(1 - p) * a for a in probs(0, m - v, p + v, v)]
	if c < EPS:
		pc = []
	elif v > c:
		pc = probs(0, m + c / 2, p + c / 2, v)
	else:
		pc = probs(c - v, m + v / 2, p + v / 2, v)
	if m < EPS:
		pm = []
	elif v > m:
		pm = probs(c + m / 2, 0, p + m / 2, v)
	else:
		pm = probs(c + v / 2, m - v, p + v / 2, v)
	return [p] + [m * a + c * b for (a, b) in zip_longest(pm, pc, fillvalue=0)]
t = read_int()
for i in range(t):
	(c, m, p, v) = read_floats()
	pb = probs(c, m, p, v)
	print(sum((a * b for (a, b) in zip(range(1, 20), pb))))


import math
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10 ** 4)

def truncate(number, decimals=0):
	if not isinstance(decimals, int):
		raise TypeError('decimal places must be an integer.')
	elif decimals < 0:
		raise ValueError('decimal places has to be 0 or more.')
	elif decimals == 0:
		return math.trunc(number)
	factor = 10.0 ** decimals
	return math.trunc(number * factor) / factor

def f(c, m, p, tot):
	m = truncate(m, 8)
	c = truncate(c, 8)
	p = truncate(p, 8)
	if c == 0 and m == 0:
		return p * tot
	elif c == 0:
		if m <= v:
			dist1 = m
		else:
			dist1 = v
		return m * f(0, max(0, m - v), p + dist1, tot + 1) + p * tot
	elif m == 0:
		if c <= v:
			dist2 = c
		else:
			dist2 = v
		return c * f(max(0, c - v), 0, p + dist2, tot + 1) + p * tot
	else:
		if m <= v:
			dist1 = m
		else:
			dist1 = v
		if c <= v:
			dist2 = c
		else:
			dist2 = v
		return m * f(c + dist1 / 2, max(0, m - v), p + dist1 / 2, tot + 1) + c * f(max(0, c - v), m + dist2 / 2, p + dist2 / 2, tot + 1) + p * tot
t = int(input())
for _ in range(t):
	(c, m, p, v) = map(float, input().split())
	print(f(c, m, p, 1))


import sys
import getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
(yes, no) = ('YES', 'NO')
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def minus_one(arr):
	return [x - 1 for x in arr]

def minus_one_matrix(mrr):
	return [[x - 1 for x in row] for row in mrr]
eps = 10 ** (-11)

def solve_(a, b, c, v):
	stack = [(a, b, c, 1, 1)]
	res = 0.0
	while stack:
		(a, b, c, t, p) = stack.pop()
		res += t * c * p
		if p < eps:
			continue
		if b >= v:
			if a > eps:
				stack.append([a + v / 2, b - v, c + v / 2, t + 1, p * b])
			else:
				stack.append([0, b - v, c + v, t + 1, p * b])
		elif a > eps:
			stack.append([a + b / 2, 0, c + b / 2, t + 1, p * b])
		else:
			stack.append([0, 0, c + b, t + 1, p * b])
		if a >= v:
			if b > eps:
				stack.append([a - v, b + v / 2, c + v / 2, t + 1, p * a])
			else:
				stack.append([a - v, 0, c + v, t + 1, p * a])
		elif b > eps:
			stack.append([0, b + a / 2, c + a / 2, t + 1, p * a])
		else:
			stack.append([0, 0, c + a, t + 1, p * a])
	return res
for case_num in range(int(input())):
	(a, b, c, v) = list(map(float, input().split()))
	res = solve(a, b, c, v)
	print(res)


import decimal

def pink(c, m, p, v, num):
	num += 1
	if c == 0 and m == 0:
		return num * p
	elif c <= v and m <= v:
		if c > 0 and m > 0:
			return num * p + c * pink(0, m + c / 2, p + c / 2, v, num) + m * pink(c + m / 2, 0, p + m / 2, v, num)
		elif c == 0:
			return num * p + m * pink(0, 0, p + m, v, num)
		elif m == 0:
			return num * p + c * pink(0, 0, p + c, v, num)
	elif c <= v and m > v:
		if c > 0:
			return num * p + c * pink(0, m + c / 2, p + c / 2, v, num) + m * pink(c + v / 2, m - v, p + v / 2, v, num)
		if c == 0:
			return num * p + m * pink(0, m - v, p + v, v, num)
	elif c > v and m <= v:
		if m > 0:
			return num * p + c * pink(c - v, m + v / 2, p + v / 2, v, num) + m * pink(c + m / 2, 0, p + m / 2, v, num)
		elif m == 0:
			return num * p + c * pink(c - v, 0, p + v, v, num)
	elif c > v and m > v:
		return num * p + c * pink(c - v, m + v / 2, p + v / 2, v, num) + m * pink(c + v / 2, m - v, p + v / 2, v, num)
ans = []
t = int(input())
for i in range(t):
	(c, m, p, v) = map(decimal.Decimal, input().split())
	ans.append(pink(c, m, p, v, 0))
for j in ans:
	print(j)


import math
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
ans = 0

def getProb(c, m, p, v, no_of_trials, accumulated_probabilty, ans1):
	global ans
	if c < 10 * -6 and m < 10 * -6:
		ans += no_of_trials * accumulated_probabilty
		return
	if c > 10 ** (-6):
		bc = c
		temporary = min(v, c)
		bc -= temporary
		if m > 10 ** (-6):
			getProb(bc, m + temporary / 2, p + temporary / 2, v, no_of_trials + 1, accumulated_probabilty * c, ans)
		else:
			getProb(bc, m, p + temporary, v, no_of_trials + 1, accumulated_probabilty * c, ans)
	if m > 10 ** (-6):
		bm = m
		temporary = min(v, m)
		bm -= temporary
		if c > 10 ** (-6):
			getProb(c + temporary / 2, bm, p + temporary / 2, v, no_of_trials + 1, accumulated_probabilty * m, ans)
		else:
			getProb(c, bm, p + temporary, v, no_of_trials + 1, accumulated_probabilty * m, ans)
	ans += accumulated_probabilty * no_of_trials * p
for jj in range(t):
	(c, m, p, v) = list(map(float, stdin.readline().rstrip().split()))
	ans = 0
	getProb(c, m, p, v, 1, 1, ans)
	print(ans)


test = int(input())

def dfs(c, m, p, v, l):
	res = p / r * l
	if c > 0:
		if c > v:
			if m > 0:
				res += c / r * dfs(c - v, m + v / 2, p + v / 2, v, l + 1)
			else:
				res += c / r * dfs(c - v, 0, p + v, v, l + 1)
		elif m > 0:
			res += c / r * dfs(0, m + c / 2, p + c / 2, v, l + 1)
		else:
			res += c / r * dfs(0, 0, p + c, v, l + 1)
	if m > 0:
		if m > v:
			if c > 0:
				res += m / r * dfs(c + v / 2, m - v, p + v / 2, v, l + 1)
			else:
				res += m / r * dfs(0, m - v, p + v, v, l + 1)
		elif c > 0:
			res += m / r * dfs(c + m / 2, 0, p + m / 2, v, l + 1)
		else:
			res += m / r * dfs(0, 0, p + m, v, l + 1)
	return res
for _ in range(test):
	(c, m, p, v) = map(float, input().split())
	r = 10 ** 6
	val = dfs(c * r, m * r, p * r, v * r, 1)
	val = '{0:.6f}'.format(val)
	print(val)


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import sys

def I():
	return int(stdin.readline())

def lint():
	return [float(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter
import math
import heapq
from heapq import heappop, heappush
import bisect
from itertools import groupby

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a // gcd(a, b) * b

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def Bs(a, x):
	i = 0
	j = 0
	left = 1
	right = x
	flag = False
	while left < right:
		mi = (left + right) // 2
		if a[mi] <= x:
			left = mi + 1
			i += 1
		else:
			right = mi
			j += 1
	if left > 0 and a[left - 1] == x:
		return (i - 1, j)
	else:
		return (-1, -1)

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a):
	print('? {}'.format(a), flush=True)
	n = I()
	return n

def dfs(i, p):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n // 2
	if n > 2:
		l.append(n)
	return l

def fun(c, m, p, v, cnt):
	if c <= 10 ** (-6) and m <= 10 ** (-6):
		return p * cnt
	(a, b) = (0, 0)
	if c > 10 ** (-6):
		q = min(v, c)
		if m <= 10 ** (-6):
			a = c * fun(c - q, 0, p + q, v, cnt + 1)
		else:
			a = c * fun(c - q, m + q / 2, p + q / 2, v, cnt + 1)
	if m > 10 ** (-6):
		q = min(v, m)
		if c <= 10 ** (-6):
			b = m * fun(0, m - q, p + q, v, cnt + 1)
		else:
			b = m * fun(c + q / 2, m - q, p + q / 2, v, cnt + 1)
	return a + b + p * cnt
t = I()
for _ in range(t):
	(c, m, p, v) = lint()
	print(fun(c, m, p, v, 1))


import math

def readint():
	return int(input())

def intline():
	return [int(e) for e in input().split()]

def mod_add(a, b):
	return (a + b) % MOD

def mod_mul(a, b):
	return a * b % MOD

def mod_pow(a, b):
	if b == 0:
		return 1
	rt = mod_pow(a, b // 2)
	res = mod_mul(rt, rt)
	if b % 2:
		res = mod_mul(res, a)
	return res

def inverse(x):
	return mod_pow(x, MOD - 2)

def mod_div(a, b):
	return mod_mul(a, inverse(b))
_cases = True
t = 1
if _cases:
	t = int(input())

class Solver:

	def solve(tc):
		denom = 10000

		def find(c, m, p, v, prob=1.0, num_mov=1):
			if prob * num_mov < 1e-08:
				return 0.0
			res = p / denom
			if not c == 0:
				diff = min(v, c)
				nc = c - diff
				if not m == 0:
					nm = m + diff / 2
					np = p + diff / 2
				else:
					nm = 0
					np = p + diff
				res += c / denom * (1 + find(nc, nm, np, v, prob * c / denom, num_mov + 1))
			if not m == 0:
				diff = min(v, m)
				nm = m - diff
				if not c == 0:
					nc = c + diff / 2
					np = p + diff / 2
				else:
					nc = 0
					np = p + diff
				res += m / denom * (1 + find(nc, nm, np, v, prob * m / denom, num_mov + 1))
			return res
		(c, m, p, v) = [int(e.split('.')[1].ljust(4, '0')) for e in input().split()]
		ans = find(c, m, p, v)
		print(ans)
for tc in range(1, t + 1):
	Solver.solve(tc)


def f(a, c):
	if a <= 1e-06:
		return 0
	else:
		return c / 2

def dfs(c, m, p, v, step, sum):
	ans = p * step * sum
	if c >= 1e-06:
		if c < v:
			ans = ans + dfs(c - c, m + f(m, c), p + c - f(m, c), v, step + 1, c * sum)
		else:
			ans = ans + dfs(c - v, m + f(m, v), p + v - f(m, v), v, step + 1, c * sum)
	if m >= 1e-06:
		if m < v:
			ans = ans + dfs(c + f(c, m), m - m, p + m - f(c, m), v, step + 1, m * sum)
		else:
			ans = ans + dfs(c + f(c, v), m - v, p + v - f(c, v), v, step + 1, m * sum)
	return ans / 1000000.0
t = int(input())
while t != 0:
	t = t - 1
	l = list(map(float, input().split()))
	ans = dfs(l[0] * 1000000.0, l[1] * 1000000.0, l[2] * 1000000.0, l[3] * 1000000.0, 1, 1)
	print(ans)


def func(c, m, p, v, n):
	ans = p * (n + 1)
	if c > x:
		a = min(c, v)
		if m > x:
			ans += c * func(c - a, m + a / 2, p + a / 2, v, n + 1)
		else:
			ans += c * func(c - a, m, p + a, v, n + 1)
	if m > x:
		a = min(m, v)
		if c > x:
			ans += m * func(c + a / 2, m - a, p + a / 2, v, n + 1)
		else:
			ans += m * func(c, m - a, p + a, v, n + 1)
	return ans
t = int(input())
x = 1e-08
for _ in range(t):
	(c, m, p, v) = map(float, input().split(' '))
	ans = func(c, m, p, v, 0)
	print('{:.12f}'.format(float(ans)))


def main():
	t = int(input())
	for i in range(t):
		(c, m, p, v) = list(map(float, input().split()))
		res = 0
		cur = [[c, m, p, 1]]
		i = 0
		while cur != []:
			nxt = []
			for node in cur:
				(c, m, p, q) = node
				if c != 0:
					if c > v + 1e-06:
						if m != 0:
							nxt.append([c - v, m + v / 2, p + v / 2, q * c])
						else:
							nxt.append([c - v, 0, p + v, q * c])
					elif m != 0:
						nxt.append([0, m + c / 2, p + c / 2, q * c])
					else:
						nxt.append([0, 0, 1, q * c])
				if m != 0:
					if m > v + 1e-06:
						if c != 0:
							nxt.append([c + v / 2, m - v, p + v / 2, q * m])
						else:
							nxt.append([0, m - v, p + v, q * m])
					elif c != 0:
						nxt.append([c + m / 2, 0, p + m / 2, q * m])
					else:
						nxt.append([0, 0, 1, q * m])
				res += p * q * (i + 1)
			cur = nxt
			i += 1
		print(res)
while True:
	try:
		main()
	except:
		break


from decimal import Decimal

def f(c, m, p, v):
	if m == 0:
		if c > v:
			return c * (1 + f(c - v, 0, p + v, v)) + p
		else:
			return 2 * c + p
	elif c == 0:
		if m > v:
			return m * (1 + f(0, m - v, p + v, v)) + p
		else:
			return 2 * m + p
	if c <= v:
		exp_if_c = f(0, m + c / 2, p + c / 2, v)
	else:
		exp_if_c = f(c - v, m + v / 2, p + v / 2, v)
	if m <= v:
		exp_if_m = f(c + m / 2, 0, p + m / 2, v)
	else:
		exp_if_m = f(c + v / 2, m - v, p + v / 2, v)
	return c * (1 + exp_if_c) + m * (1 + exp_if_m) + p
for _ in range(int(input())):
	(c, m, p, v) = map(Decimal, input().split())
	print(f(c, m, p, v))


r = 1000000000.0

def check(c, m, p, v, l):
	ans = p / r * l
	if c > 0:
		if c > v:
			if m > 0:
				ans += c / r * check(c - v, m + v / 2, p + v / 2, v, l + 1)
			else:
				ans += c / r * check(c - v, 0, p + v, v, l + 1)
		elif m > 0:
			ans += c / r * check(0, m + c / 2, p + c / 2, v, l + 1)
		else:
			ans += c / r * check(0, 0, p + c, v, l + 1)
	if m > 0:
		if m > v:
			if c > 0:
				ans += m / r * check(c + v / 2, m - v, p + v / 2, v, l + 1)
			else:
				ans += m / r * check(0, m - v, p + v, v, l + 1)
		elif c > 0:
			ans += m / r * check(c + m / 2, 0, p + m / 2, v, l + 1)
		else:
			ans += m / r * check(0, 0, p + m, v, l + 1)
	return ans
test = int(input())
for i in range(test):
	lst = [float(i) for i in input().split()][:4]
	(c, m, p, v) = (lst[0], lst[1], lst[2], lst[3])
	c = c * r
	m = m * r
	p = p * r
	v = v * r
	ans = 0.0
	ans = check(c, m, p, v, 1)
	print(ans)


import sys
import math
mod = 10 ** 9 + 7
LI = lambda : [float(k) for k in input().split()]
input = lambda : sys.stdin.readline().rstrip()
IN = lambda : int(input())
S = lambda : input()
r = range

def cplay(c, m, p, v, pro, car):
	if p > 0.99999:
		return
	global ans
	if c > v:
		if m > 1e-05:
			m += v / 2
			p += v / 2
		else:
			p += v
		pro *= c
		car += 1
		c -= v
		ans += car * pro * p
		if c > 1e-05:
			cplay(c, m, p, v, pro, car)
		if m > 1e-05:
			mplay(c, m, p, v, pro, car)
	elif c > 1e-05:
		if m > 1e-05:
			m += c / 2
			p += c / 2
		else:
			p += c
		pro *= c
		c = 0
		car += 1
		ans += car * pro * p
		if m > 1e-05:
			mplay(c, m, p, v, pro, car)

def mplay(c, m, p, v, pro, car):
	if p > 0.99999:
		return
	global ans
	if m > v:
		if c > 1e-05:
			c += v / 2
			p += v / 2
		else:
			p += v
		pro *= m
		car += 1
		m -= v
		ans += car * pro * p
		if c > 1e-05:
			cplay(c, m, p, v, pro, car)
		if m > 1e-05:
			mplay(c, m, p, v, pro, car)
	elif m > 1e-05:
		if c > 1e-05:
			c += m / 2
			p += m / 2
		else:
			p += m
		pro *= m
		m = 0
		car += 1
		ans += car * pro * p
		if c > 1e-05:
			cplay(c, m, p, v, pro, car)
for t in r(IN()):
	(c, m, p, v) = LI()
	ans = p
	if c > 1e-05:
		cplay(c, m, p, v, 1, 1)
	if m > 1e-05:
		mplay(c, m, p, v, 1, 1)
	print('%.12f' % ans)


from fractions import Fraction
T = int(input())
eps = 1e-08
for _ in range(T):
	(C, M, P, V) = map(float, input().split(' '))

	def go(c, m, p, v, n):
		res = p * (n + 1)
		if c > eps:
			t = min(c, v)
			if m > eps:
				res += c * go(c - t, m + t / 2, p + t / 2, v, n + 1)
			else:
				res += c * go(c - t, m, p + t, v, n + 1)
		if m > eps:
			t = min(m, v)
			if c > eps:
				res += m * go(c + t / 2, m - t, p + t / 2, v, n + 1)
			else:
				res += m * go(c, m - t, p + t, v, n + 1)
		return res
	res = go(C, M, P, V, 0)
	print('{:.12f}'.format(float(res)))


from sys import stdin
from collections import deque
TO_INT = 10 ** 10
TO_FLOAT = 10 ** (-10)
EPSILON = 10

def solve():
	(c, m, p, v) = map(lambda x: int(float(x) * TO_INT), stdin.readline().split())
	q = deque()
	q.append([c, m, p, 1, 1.0])
	ans = 0
	while 0 < len(q) < 10 ** 5:
		now = q.popleft()
		if now[2] < EPSILON:
			continue
		ans += now[2] * TO_FLOAT * now[3] * now[4]
		if now[0] < EPSILON and now[1] < EPSILON:
			continue
		if now[0] < EPSILON:
			if now[1] <= v + EPSILON:
				q.append([0, 0, 1 * TO_INT, now[3] + 1, now[4] * now[1] * TO_FLOAT])
			else:
				q.append([0, now[1] - v, TO_INT - now[1] + v, now[3] + 1, now[4] * now[1] * TO_FLOAT])
			continue
		if now[1] < EPSILON:
			if now[0] <= v + EPSILON:
				q.append([0, 0, 1 * TO_INT, now[3] + 1, now[4] * now[0] * TO_FLOAT])
			else:
				q.append([now[0] - v, 0, 1 * TO_INT - now[0] + v, now[3] + 1, now[4] * now[0] * TO_FLOAT])
			continue
		if now[0] <= v + EPSILON:
			new_c = 0
			new_m = now[1] + now[0] // 2
			new_p = now[2] + now[0] // 2
			wow = new_m + new_p
			new_m = int(new_m / wow * TO_INT)
			new_p = int(new_p / wow * TO_INT)
			foo = [new_c, new_m, new_p, now[3] + 1, now[4] * now[0] * TO_FLOAT]
		else:
			new_c = now[0] - v
			new_m = now[1] + v // 2
			new_p = now[2] + v // 2
			foo = [new_c, new_m, new_p, now[3] + 1, now[4] * now[0] * TO_FLOAT]
		q.append(foo)
		if now[1] <= v + EPSILON:
			new_c = now[0] + now[1] // 2
			new_m = 0
			new_p = now[2] + now[1] // 2
			wow = new_c + new_p
			new_c = int(new_c / wow * TO_INT)
			new_p = int(new_p / wow * TO_INT)
			foo = [new_c, new_m, new_p, now[3] + 1, now[4] * now[1] * TO_FLOAT]
		else:
			new_c = now[0] + v // 2
			new_m = now[1] - v
			new_p = now[2] + v // 2
			foo = [new_c, new_m, new_p, now[3] + 1, now[4] * now[1] * TO_FLOAT]
		q.append(foo)
	return ans
t = int(stdin.readline().strip())
for _ in range(t):
	print(solve())


t = int(input())

def zero(x):
	return abs(x) < 1e-09

def expectation(c, m, p, v):
	if zero(c) and zero(m):
		return 1
	elif zero(c):
		return 1 + m * expectation(c, m - min(m, v), p + min(m, v), v)
	elif zero(m):
		return 1 + c * expectation(c - min(c, v), m, p + min(c, v), v)
	else:
		inc1 = min(c, v)
		inc2 = min(m, v)
		return 1 + c * expectation(c - inc1, m + inc1 / 2, p + inc1 / 2, v) + m * expectation(c + inc2 / 2, m - inc2, p + inc2 / 2, v)
for case in range(t):
	(c, m, p, v) = [float(x) for x in input().split()]
	print(expectation(c, m, p, v))


import sys, os
from math import *
from bisect import *
from heapq import *
from collections import *
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		eps = 1e-09
		(c, m, p, v) = map(float, input().split())

		def rec(c, m, p):
			out = p
			if c > eps:
				if c - v > eps:
					if m > eps:
						out += c * (1 + rec(c - v, m + v / 2, p + v / 2))
					else:
						out += c * (1 + rec(c - v, m, p + v))
				elif m > eps:
					out += c * (1 + rec(0, m + c / 2, p + c / 2))
				else:
					out += c * (1 + rec(0, m, p + c))
			if m > eps:
				if m - v > eps:
					if c > eps:
						out += m * (1 + rec(c + v / 2, m - v, p + v / 2))
					else:
						out += m * (1 + rec(c, m - v, p + v))
				elif c > eps:
					out += m * (1 + rec(c + m / 2, 0, p + m / 2))
				else:
					out += m * (1 + rec(c, 0, p + m))
			return out
		print(rec(c, m, p))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def MI():
	return map(int, input().split())

def outP(var):
	sys.stdout.write(str(var) + '\n')
MOD = 10 ** 9 + 7
mod = 998244353
main()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def calc(a, b, c, v, s):
	if a == 0 and b == 0:
		return c * s
	eps = 10 ** (-8)
	res = 0
	if a > eps:
		l = min(a, v)
		if b > eps:
			res += a * calc(a - l, b + l / 2, c + l / 2, v, s + 1)
		else:
			res += a * calc(a - l, 0, c + l, v, s + 1)
	if b > eps:
		l = min(b, v)
		if a > eps:
			res += b * calc(a + l / 2, b - l, c + l / 2, v, s + 1)
		else:
			res += b * calc(0, b - l, c + l, v, s + 1)
	return s * c + res
t = int(input())
for _ in range(t):
	(c, m, p, v) = map(float, input().split())
	print(calc(c, m, p, v, 0) + 1)


import sys
sys.stderr = sys.stdout
K = 1000000

def solve(c, m, p, v):
	log('c', c, 'm', m, 'p', p, 'v', v)
	c = int(round(c * K))
	m = int(round(m * K))
	p = int(round(p * K))
	v = int(round(v * K))
	log('c', c, 'm', m, 'p', p, 'v', v)
	v2 = v // 2
	S = [(c, m, p, 1.0)]
	t = 0.0
	while S:
		T = []
		for s in S:
			if len(s) == 4:
				(c, m, p, f) = s
				t += f
				if c > v:
					T.append((c - v, m + v2, p + v2, f * (c / K)))
				else:
					c2 = c // 2
					T.append((m + c2, p + c2, f * (c / K)))
				if m > v:
					T.append((c + v2, m - v, p + v2, f * (m / K)))
				else:
					m2 = m // 2
					T.append((c + m2, p + m2, f * (m / K)))
			elif len(s) == 3:
				(m, p, f) = s
				t += f
				m_ = m - v
				if m > v:
					T.append((m - v, p + v, f * (m / K)))
				else:
					T.append((10000000, f * (m / K)))
			elif len(s) == 2:
				(p, f) = s
				t += f
			else:
				raise AssertionError(s)
		S = T
	return t

def case():
	(c, m, p, v) = map(float, input().split())
	t = solve(c, m, p, v)
	return f'{t:0.12f}'

def main():
	t = readint()
	print('\n'.join((case() for _ in range(t))))

def readint():
	return int(input())

def readinti():
	return map(int, input().split())

def readintt():
	return tuple(readinti())

def readintl():
	return list(readinti())

def readinttl(k):
	return [readintt() for _ in range(k)]

def readintll(k):
	return [readintl() for _ in range(k)]

def lstr(l):
	return ' '.join(map(str, l))

def llstr(ll):
	return '\n'.join(map(lstr, ll))

def log(*args, **kwargs):
	print(*args, **kwargs, file=sys.__stderr__)
main()


import sys
input = sys.stdin.readline
scale = 40000
for _ in range(int(input())):
	(c, m, p, v) = map(float, input().split())
	(c, m, p, v) = (c * scale, m * scale, p * scale, v * scale)

	def dfs(c, m, p):
		ans = 1
		if c:
			x = min(v, c)
			if not m:
				ans += c / scale * dfs(c - x, 0, p + x)
			else:
				ans += c / scale * dfs(c - x, m + x / 2, p + x / 2)
		if m:
			x = min(v, m)
			if not c:
				ans += m / scale * dfs(0, m - x, p + x)
			else:
				ans += m / scale * dfs(c + x / 2, m - x, p + x / 2)
		return ans
	print(dfs(c, m, p))


t = int(input())

def is_zero(x):
	return abs(x) < 1e-09

def EV(x, y, z, v):
	if is_zero(x) and is_zero(y):
		return 1
	elif is_zero(x):
		step = min(y, v)
		return 1 + y * EV(x, y - step, z + step, v)
	elif is_zero(y):
		step = min(x, v)
		return 1 + x * EV(x - step, y, z + step, v)
	else:
		step1 = min(x, v)
		step2 = min(y, v)
		return 1 + x * EV(x - step1, y + step1 / 2, z + step1 / 2, v) + y * EV(x + step2 / 2, y - step2, z + step2 / 2, v)
for test in range(t):
	(c, m, p, v) = [float(x) for x in input().split()]
	print(EV(c, m, p, v))


import sys

def input():
	return sys.stdin.readline().rstrip()
DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)]
maxn = 10000
fixed = 1 << 30
from collections import defaultdict

def main():
	t = int(input())
	memo = defaultdict(int)

	def slv(c, m, p, v):
		if (c, m, p, v) in memo:
			return memo[c, m, p, v]
		if c == 0 and m == 0:
			memo[c, m, p, v] = 1
			return 1
		else:
			res = 0
			if c == 0:
				if m <= v:
					res = p / (p + m) + (slv(0, 0, m + p, v) + 1) * m / (p + m)
				else:
					res = p / (p + m) + (slv(0, m - v, p + v, v) + 1) * m / (p + m)
				memo[c, m, p, v] = res
				return res
			elif m == 0:
				if c <= v:
					res = p / (p + c) + (slv(0, 0, c + p, v) + 1) * c / (p + c)
				else:
					res = p / (p + c) + (slv(c - v, 0, p + v, v) + 1) * c / (p + c)
				memo[c, m, p, v] = res
				return res
			else:
				res = p / (c + m + p)
				if c <= v:
					res += (slv(0, c // 2 + m, c // 2 + p, v) + 1) * c / (c + m + p)
				else:
					res += (slv(c - v, v // 2 + m, v // 2 + p, v) + 1) * c / (c + m + p)
				if m <= v:
					res += (slv(m // 2 + c, 0, m // 2 + p, v) + 1) * m / (c + m + p)
				else:
					res += (slv(v // 2 + c, m - v, v // 2 + p, v) + 1) * m / (c + m + p)
				memo[c, m, p, v] = res
				return res
	for i in range(t):
		(c, m, p, v) = map(float, input().split())
		(c, m, p, v) = (int(c * maxn * fixed), int(m * maxn * fixed), int(p * maxn * fixed), int(v * maxn * fixed))
		expv = slv(c, m, p, v)
		print(expv)
	return 0
main()


import sys
sys.setrecursionlimit(10 ** 5)
result = 0
eps = 1e-09

def pink(c, m, p, v, prob, step):
	global result, eps
	if c > eps:
		if c - v > eps:
			if m > eps:
				pink(c - v, m + v / 2, p + v / 2, v, prob * c, step + 1)
			else:
				pink(c - v, m, p + v, v, prob * c, step + 1)
		elif m > eps:
			pink(0, m + c / 2, p + c / 2, v, prob * c, step + 1)
		else:
			pink(0, m, p + c, v, prob * c, step + 1)
	if m > eps:
		if m - v > eps:
			if c > eps:
				pink(c + v / 2, m - v, p + v / 2, v, prob * m, step + 1)
			else:
				pink(c, m - v, p + v, v, prob * m, step + 1)
		elif c > eps:
			pink(c + m / 2, 0, p + m / 2, v, prob * m, step + 1)
		else:
			pink(c, 0, p + m, v, prob * m, step + 1)
	if p > eps:
		result += prob * p * step
	return
num = int(sys.stdin.readline().strip())
for k in range(num):
	(c, m, p, v) = map(float, sys.stdin.readline().split())
	pink(c, m, p, v, 1, 1)
	print(result)
	result = 0


import sys
input = sys.stdin.readline
shift = 10 ** 4
ans = 0

def solve(c, m, p, v, races, prob):
	global ans
	ans += (races + 1) * prob * p / shift
	if c > v:
		if m == 0:
			solve(c - v, 0, p + v, v, races + 1, prob * c / shift)
		else:
			solve(c - v, m + v / 2, p + v / 2, v, races + 1, prob * c / shift)
	elif c > 0:
		if m == 0:
			solve(0, 0, shift, v, races + 1, prob * c / shift)
		else:
			solve(0, m + c / 2, p + c / 2, v, races + 1, prob * c / shift)
	if m > v:
		if c == 0:
			solve(c, m - v, p + v, v, races + 1, prob * m / shift)
		else:
			solve(c + v / 2, m - v, p + v / 2, v, races + 1, prob * m / shift)
	elif m > 0:
		if c == 0:
			solve(0, 0, shift, v, races + 1, prob * m / shift)
		else:
			solve(c + m / 2, 0, p + m / 2, v, races + 1, prob * m / shift)
for _ in range(int(input())):
	a = list(map(lambda x: str(x[2:]), input().split()))
	for i in range(4):
		a[i] = int(a[i]) * 10 ** (4 - len(a[i]))
	(c, m, p, v) = a
	ans = 0
	solve(c, m, p, v, 0, 1)
	print(ans)


def process(c, m, p, v):
	d = {'': [1, (c, m, p), (True, True, True)]}
	I = 1
	answer = 0
	while len(d) > 0:
		d2 = {}
		for x in d:
			(prob, t, R) = d[x]
			(c2, m2, p2) = t
			(c_r, m_r, p_r) = R
			for i in range(3):
				if i == 0 and R[0]:
					step = 'C'
					if c2 > v and c2 - v > 1e-05:
						if R[1]:
							t2 = [c2 - v, m2 + v / 2, p2 + v / 2]
							d2[x + step] = [prob * c2, t2, R]
						else:
							t2 = [c2 - v, 0, p2 + v]
							d2[x + step] = [prob * c2, t2, R]
					elif R[1]:
						t2 = [0, m2 + c2 / 2, p2 + c2 / 2]
						d2[x + step] = [prob * c2, t2, (False, m_r, p_r)]
					else:
						t2 = [0, 0, 1]
						d2[x + step] = [prob * c2, t2, (False, m_r, p_r)]
				elif i == 1 and R[1]:
					step = 'M'
					if m2 > v and m2 - v > 1e-05:
						if R[0]:
							t2 = [c2 + v / 2, m2 - v, p2 + v / 2]
							d2[x + step] = [prob * m2, t2, R]
						else:
							t2 = [0, m2 - v, p2 + v]
							d2[x + step] = [prob * m2, t2, R]
					elif R[0]:
						t2 = [c2 + m2 / 2, 0, p2 + m2 / 2]
						d2[x + step] = [prob * m2, t2, (c_r, False, p_r)]
					else:
						t2 = [0, 0, 1]
						d2[x + step] = [prob * m2, t2, (c_r, False, p_r)]
				elif i == 2:
					answer += I * prob * p2
		I += 1
		d = d2
	return answer
t = int(input())
for i in range(t):
	(c, m, p, v) = [float(x) for x in input().split()]
	print(process(c, m, p, v))


from decimal import *

def numMoves(c, m, p, v):
	ans = 1
	if c != -1:
		if c <= v:
			if m != -1:
				ans += c * numMoves(-1, m + c / 2, p + c / 2, v)
			else:
				ans += c * numMoves(-1, m, p + c, v)
		elif m != -1:
			ans += c * numMoves(c - v, m + v / 2, p + v / 2, v)
		else:
			ans += c * numMoves(c - v, m, p + v, v)
	if m != -1:
		if m <= v:
			if c != -1:
				ans += m * numMoves(c + m / 2, -1, p + m / 2, v)
			else:
				ans += m * numMoves(c, -1, p + m, v)
		elif c != -1:
			ans += m * numMoves(c + v / 2, m - v, p + v / 2, v)
		else:
			ans += m * numMoves(c, m - v, p + v, v)
	return ans
test_cases = int(input())
for test_case in range(test_cases):
	abc = input().split()
	c = Decimal(abc[0])
	m = Decimal(abc[1])
	p = Decimal(abc[2])
	v = Decimal(abc[3])
	print(numMoves(c, m, p, v))


import math
import heapq
import sys
input = sys.stdin.readline
S = lambda : input()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7

def solve(c, m, p, v, s, res, a):
	if len(s) != 0 and s[-1] == 'P':
		res[0] += len(s) * a
		return
	solve(c, m, p, v, s + 'P', res, a * p)
	if c > pow(10, -6):
		if c > v:
			k = 1
			if m > pow(10, -6):
				k += 1
			x = v / k
			if m > pow(10, -6):
				t = m + x
			else:
				t = m
			solve(c - v, t, p + x, v, s + 'C', res, a * c)
		else:
			k = 1
			if m > pow(10, -6):
				k += 1
			x = c / k
			if m > pow(10, -6):
				t = m + x
			else:
				t = m
			solve(0, t, p + x, v, s + 'C', res, a * c)
	if m > pow(10, -6):
		if m > v:
			k = 1
			if c > pow(10, -6):
				k += 1
			x = v / k
			if c > pow(10, -6):
				t = c + x
			else:
				t = c
			solve(t, m - v, p + x, v, s + 'M', res, a * m)
		else:
			k = 1
			if c > pow(10, -6):
				k += 1
			x = m / k
			if c > pow(10, -6):
				t = c + x
			else:
				t = c
			solve(t, 0, p + x, v, s + 'M', res, a * m)
for _ in range(I()):
	(c, m, p, v) = map(float, input().split())
	res = [0]
	solve(c, m, p, v, '', res, 1)
	print(res[0])


import sys, threading
sys.setrecursionlimit(6100)
threading.stack_size()
thread = threading.Thread()
thread.start()
t = int(input())
zero = 0
to = 2

def solve(curr, pro, l, c, m, p):
	if pro == zero:
		return
	if curr == 'p':
		pro *= p
		ans.append((pro, l))
		return
	if curr == 'c':
		if c == zero:
			return
		pro *= c
		pro /= 10 ** 8
		if c <= v:
			if m != 0:
				m += c / to
				p += c / to
			else:
				p += c
			c = zero
		else:
			if m != zero:
				m += v / to
				p += v / to
			else:
				p += v
			c -= v
		solve('c', pro, l + 1, c, m, p)
		solve('m', pro, l + 1, c, m, p)
		solve('p', pro, l + 1, c, m, p)
	else:
		if m == zero:
			return
		pro *= m
		pro /= 10 ** 8
		if m <= v:
			if c != zero:
				c += m / to
				p += m / to
			else:
				p += m
			m = zero
		else:
			if c != zero:
				c += v / to
				p += v / to
			else:
				p += v
			m -= v
		solve('c', pro, l + 1, c, m, p)
		solve('m', pro, l + 1, c, m, p)
		solve('p', pro, l + 1, c, m, p)
	return
while t:
	t -= 1
	(c, m, p, v) = [int(float(x) * 10 ** 8) for x in input().split()]
	ans = []
	solve('c', 1, 1, c, m, p)
	solve('m', 1, 1, c, m, p)
	solve('p', 1, 1, c, m, p)
	s = 0
	for a in ans:
		s += a[0] * a[1]
	print(s / 10 ** 8)


from itertools import product
import itertools
import sys
import heapq
from collections import deque
MOD = 1000000000007

def find(parent, i):
	if parent[i] != i:
		parent[i] = find(parent, parent[i])
	return parent[i]

def union(parent, rank, xx, yy):
	x = find(parent, xx)
	y = find(parent, yy)
	if rank[x] > rank[y]:
		parent[y] = x
	elif rank[y] > rank[x]:
		parent[x] = y
	else:
		parent[y] = x
		rank[x] += 1
ans = 0
K = int(sys.stdin.readline().strip())
x = 0
y = 0
for _ in range(K):
	(c, m, p, v) = list(map(float, sys.stdin.readline().strip().split()))
	stack = deque([(c, m, p, 1, 1)])
	ans = 0
	while stack:
		(c, m, p, kk, w) = stack.popleft()
		ans += p * w * kk
		if c - 1e-07 > 0:
			k = c * kk
			if c <= v:
				if m - 1e-07 > 0:
					stack.append((0, m + c / 2, p + c / 2, k, w + 1))
				else:
					stack.append((0, 0, p + c, k, w + 1))
			elif m - 1e-07 > 0:
				stack.append((c - v, m + v / 2, p + v / 2, k, w + 1))
			else:
				stack.append((c - v, m, p + v, k, w + 1))
		if m - 1e-07 > 0:
			k = m * kk
			if m <= v:
				if c - 1e-07 > 0:
					stack.append((c + m / 2, 0, p + m / 2, k, w + 1))
				else:
					stack.append((c, 0, p + m, k, w + 1))
			elif c - 1e-07 > 0:
				stack.append((c + v / 2, m - v, p + v / 2, k, w + 1))
			else:
				stack.append((c, m - v, p + v, k, w + 1))
	print(ans)


from fractions import Fraction

def mean(c, m, p, v):

	def nonZero(a):
		return abs(a) > 1e-07
	r1 = 0.0
	if 0.0 < c <= v:
		if nonZero(m):
			r1 = 1.0 + mean(0.0, m + c / 2, p + c / 2, v)
		else:
			r1 = 1.0 + mean(0.0, 0.0, p + c, v)
	elif v < c:
		if nonZero(m):
			r1 = 1.0 + mean(c - v, m + v / 2, p + v / 2, v)
		else:
			r1 = 1.0 + mean(c - v, 0.0, p + v, v)
	r2 = 0.0
	if 0.0 < m <= v:
		if nonZero(c):
			r2 = 1.0 + mean(c + m / 2, 0.0, p + m / 2, v)
		else:
			r2 = 1.0 + mean(0.0, 0.0, p + m, v)
	elif v < m:
		if nonZero(c):
			r2 = 1.0 + mean(c + v / 2, m - v, p + v / 2, v)
		else:
			r2 = 1.0 + mean(0.0, m - v, p + v, v)
	r3 = 1.0
	return c * r1 + m * r2 + p * r3
T = int(input())
for _ in range(T):
	(c, m, p, v) = map(float, input().split(' '))
	print(mean(c, m, p, v))


from decimal import Decimal
from functools import lru_cache
one = Decimal(1)

@lru_cache
def g(c, p, v):
	if p == one:
		return one
	res = one
	if c <= v:
		res += c
	else:
		res += c * g(c - v, p + v, v)
	return res

@lru_cache
def f(c, m, p, v):
	if p == 1:
		return one
	res = one
	if m <= v:
		res += m * g(c + m / 2, p + m / 2, v)
	else:
		res += m * f(c + v / 2, m - v, p + v / 2, v)
	if c <= v:
		res += c * g(m + c / 2, p + c / 2, v)
	else:
		res += c * f(c - v, m + v / 2, p + v / 2, v)
	return res

def solve():
	(c, m, p, v) = map(Decimal, input().split())
	return f(c, m, p, v)

def main():
	t = int(input())
	for i in range(t):
		print(solve())
main()


cache = {}

def expected(P, v):
	(c, m, p) = P
	ans = p
	if 0 < c:
		P1 = [c, m, p]
		if c <= v:
			P1 = [0, 0, p + c] if m == 0 else [0, m + c / 2, p + c / 2]
		if c > v:
			P1 = [c - v, 0, p + v] if m == 0 else [c - v, m + v / 2, p + v / 2]
		ans += c * (1 + expected(P1, v))
	if 0 < m:
		P2 = [c, m, p]
		if m <= v:
			P2 = [0, 0, p + m] if c == 0 else [c + m / 2, 0, p + m / 2]
		if m > v:
			P2 = [0, m - v, p + v] if c == 0 else [c + v / 2, m - v, p + v / 2]
		ans += m * (1 + expected(P2, v))
	return ans * 0.0001
t = int(input())
for _ in range(t):
	L = list(map(float, input().split()))
	(P, v) = (L[:3], L[3])
	P = [x * 10000 for x in P]
	v = 10000 * v
	print(expected(P, v))


t = int(input())

def expect(c, m, p, v):
	l = 1e-06
	res = 0
	res += p
	if m > v and c > l:
		res += (1 + expect(c + v / 2, m - v, p + v / 2, v)) * m
	if c > v and m > l:
		res += (1 + expect(c - v, m + v / 2, p + v / 2, v)) * c
	if m <= v and m > l and (c > l):
		res += (1 + expect(c + m / 2, 0, p + m / 2, v)) * m
	if c <= v and m > l and (c > l):
		res += (1 + expect(0, m + c / 2, p + c / 2, v)) * c
	if c <= l and m > l:
		if m > v:
			res += (1 + expect(0, m - v, p + v, v)) * m
		else:
			res += (1 + expect(0, 0, p + m, v)) * m
	if m <= l and c > l:
		if c > v:
			res += (1 + expect(c - v, 0, p + v, v)) * c
		else:
			res += (1 + expect(0, 0, p + c, v)) * c
	return res
for _ in range(t):
	(c, m, p, v) = [float(x) for x in input().split()]
	print(expect(c, m, p, v))


def dfs(c, m, p, v, op):
	if c == 0 and m == 0:
		return op * 1.0
	sum = 0.0
	sum = sum + p / 1000000.0 * op * 1.0
	if c != 0:
		if c < v:
			if m == 0:
				sum = sum + c / 1000000.0 * dfs(0, 0, p + c, v, op + 1)
			else:
				sum = sum + c / 1000000.0 * dfs(0, m + c / 2, p + c / 2, v, op + 1)
		elif m == 0:
			sum = sum + c / 1000000.0 * dfs(c - v, 0, p + v, v, op + 1)
		else:
			sum = sum + c / 1000000.0 * dfs(c - v, m + v / 2, p + v / 2, v, op + 1)
	if m != 0:
		if m < v:
			if c == 0:
				sum = sum + m / 1000000.0 * dfs(0, 0, p + m, v, op + 1)
			else:
				sum = sum + m / 1000000.0 * dfs(c + m / 2, 0, p + m / 2, v, op + 1)
		elif c == 0:
			sum = sum + m / 1000000.0 * dfs(0, m - v, p + v, v, op + 1)
		else:
			sum = sum + m / 1000000.0 * dfs(c + v / 2, m - v, p + v / 2, v, op + 1)
	return sum
t = int(input())
while t:
	(c, m, p, v) = map(float, input().split())
	c = c * 1000000.0
	m = m * 1000000.0
	p = p * 1000000.0
	v = v * 1000000.0
	print(dfs(c, m, p, v, 1))
	t = t - 1


from math import ceil
t = int(input())
E = 10 ** (-6)

def solve(probs, ans, current_prob, picked):
	(c, m, p, v) = probs
	if picked:
		if picked[-1] == 'p':
			a = p * current_prob
			ans.append(a * len(picked))
			return
		elif picked[-1] == 'c':
			if c <= E:
				return
			r = c if c - v <= E else v
			current_prob *= c
			c -= v
			if m > E:
				m += r / 2
				p += r / 2
			else:
				p += r
		elif picked[-1] == 'm':
			if m <= E:
				return
			r = m if m - v <= E else v
			current_prob *= m
			m -= v
			if c > E:
				c += r / 2
				p += r / 2
			else:
				p += r
	for o in ['c', 'm', 'p']:
		solve([c, m, p, v], ans, current_prob, picked + [o])
for _ in range(t):
	probs = list(map(float, input().split()))
	ans = []
	solve(probs, ans, 1, [])
	print(sum(ans))


import sys
eps = 1e-05

def expect(c, m, p, v, itr):
	if abs(c) < eps and abs(m) < eps:
		return itr * p
	if abs(c) < eps:
		mv = max(m - v, 0)
		return itr * p + m * expect(0, mv, p + m - mv, v, itr + 1)
	if abs(m) < eps:
		cv = max(c - v, 0)
		return itr * p + c * expect(cv, 0, p + c - cv, v, itr + 1)
	cv = max(c - v, 0)
	mv = max(m - v, 0)
	dc = (c - cv) / 2
	dm = (m - mv) / 2
	return itr * p + c * expect(cv, m + dc, p + dc, v, itr + 1) + m * expect(c + dm, mv, p + dm, v, itr + 1)
t = int(input())
for _ in range(t):
	q = list(map(float, input().split()))
	print(expect(q[0], q[1], q[2], q[3], 1))


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
zero = 10 ** (-7)
ans = 0
total = 0

def fun(c, m, p, v, cnt, prob):
	global ans
	global zero
	ans += p * cnt * prob
	if c != 0:
		prob1 = prob * c
		v1 = min(c, v)
		c1 = c - v
		if m != 0:
			m1 = m + v1 / 2
			p1 = p + v1 / 2
		else:
			m1 = 0
			p1 = p + v1
		if c1 < zero:
			c1 = 0
		fun(c1, m1, p1, v, cnt + 1, prob1)
	if m != 0:
		prob1 = prob * m
		v1 = min(m, v)
		m1 = m - v
		if c != 0:
			c1 = c + v1 / 2
			p1 = p + v1 / 2
		else:
			c1 = 0
			p1 = p + v1
		if m1 < zero:
			m1 = 0
		fun(c1, m1, p1, v, cnt + 1, prob1)
for _ in range(int(input())):
	(c, m, p, v) = [float(i) for i in input().split()]
	ans = 0
	fun(c, m, p, v, 1, 1)
	print(str.format('{0:.9f}', ans))


import sys
input = sys.stdin.buffer.readline
from collections import deque
for _ in range(int(input())):
	(c, m, p, v) = map(float, input().split())
	queue = deque()
	queue.append([c, m, p, 1, 1])
	ans = 0
	total = 0
	while queue:
		(c, m, p, count, value) = queue.popleft()
		ans += value * p * count
		if c == 0 and m == 0:
			continue
		if c > 1e-08:
			if c <= v:
				c_dash = 0
			else:
				c_dash = max(0, c - v)
			e = c - c_dash
			d = e / 2
			if m > 1e-08:
				queue.append([c_dash, m + d, p + d, count + 1, value * c])
			else:
				queue.append([c_dash, m, p + e, count + 1, value * c])
		if m > 1e-08:
			if m <= v:
				m_dash = 0
			else:
				m_dash = max(0, m - v)
			e = m - m_dash
			d = e / 2
			if c > 1e-08:
				queue.append([c + d, m_dash, p + d, count + 1, value * m])
			else:
				queue.append([c, m_dash, p + e, count + 1, value * m])
		total += 1
	print(ans)


blanck = []
from sys import setrecursionlimit

def rec(a, b, c, v, p, card):
	if a == 0 and b == 0 or c >= 1:
		blanck.append(p * card)
		return
	l = [a, b, c]
	for i in range(3):
		if i != 2 and l[i] > 1e-08:
			if i == 0:
				ta = l[i]
				dd = min(l[i], v)
				if b > 1e-08:
					rec(ta - dd, b + dd / 2, c + dd / 2, v, p * l[i], card + 1)
				else:
					rec(ta - dd, 0, c + dd, v, p * l[i], card + 1)
			if i == 1:
				tb = l[i]
				dd = min(l[i], v)
				if a > 1e-08:
					rec(a + dd / 2, tb - dd, c + dd / 2, v, p * l[i], card + 1)
				else:
					rec(0, tb - dd, c + dd, v, p * l[i], card + 1)
		if i == 2:
			blanck.append(p * c * card)
for t in range(int(input())):
	blanck = []
	(a, b, c, d) = map(float, input().strip().split())
	rec(a, b, c, d, 1, 1)
	ans = 0.0
	for i in blanck:
		if i != float('inf'):
			ans += i
	print(ans)


t = int(input())
THR = 1e-09

def calc(c, m, p, v, n):
	ans = p * n
	if c < THR and m < THR:
		return ans
	if c >= 0:
		if c > v:
			if m < THR:
				ans += c * calc(c - v, -1, p + v, v, n + 1)
			else:
				ans += c * calc(c - v, m + v / 2, p + v / 2, v, n + 1)
		elif m < THR:
			ans += c * calc(-1, -1, 1, v, n + 1)
		else:
			ans += c * calc(-1, m + c / 2, p + c / 2, v, n + 1)
	if m >= 0:
		if m > v:
			if c < THR:
				ans += m * calc(-1, m - v, p + v, v, n + 1)
			else:
				ans += m * calc(c + v / 2, m - v, p + v / 2, v, n + 1)
		elif c < THR:
			ans += m * calc(-1, -1, 1, v, n + 1)
		else:
			ans += m * calc(c + m / 2, -1, p + m / 2, v, n + 1)
	return ans
for i in range(t):
	(c, m, p, v) = [float(j) for j in input().split()]
	print(calc(c, m, p, v, 1))


def expected(c, m, p, v):
	E = 1.0
	if c > 1e-07:
		if m <= 1e-07:
			E += c * expected(c - min(c, v), m, p + min(c, v), v)
		else:
			E += c * expected(c - min(c, v), m + min(c, v) / 2.0, p + min(c, v) / 2.0, v)
	if m > 1e-07:
		if c <= 1e-07:
			E += m * expected(c, m - min(m, v), p + min(m, v), v)
		else:
			E += m * expected(c + min(m, v) / 2.0, m - min(m, v), p + min(m, v) / 2.0, v)
	return E
t = int(input())
for _ in range(t):
	(c, m, p, v) = [float(x) for x in input().split()]
	print(expected(c, m, p, v))


answers = []

def solve(c, m, p, v):
	queue = [[1, 1, [c, m, p]]]
	ans = 0
	while queue:
		(prevProb, count, array) = queue.pop()
		length = len(array)
		ans += prevProb * count * array[-1]
		if length == 1:
			continue
		for i in range(length - 1):
			prob = array[i]
			toBeAdded = 0
			if prob <= v:
				toBeAdded = prob
			else:
				toBeAdded = v
			eachItemShare = toBeAdded / (length - 1)
			if prob <= v:
				if length == 2:
					queue.append([prevProb * prob, count + 1, [float('%.6f' % (array[-1] + eachItemShare))]])
				elif i == 0:
					queue.append([prevProb * prob, count + 1, [float('%.6f' % (array[-2] + eachItemShare)), float('%.6f' % (array[-1] + eachItemShare))]])
				else:
					queue.append([prevProb * prob, count + 1, [float('%.6f' % (array[0] + eachItemShare)), float('%.6f' % (array[-1] + eachItemShare))]])
			elif length == 2:
				queue.append([prevProb * prob, count + 1, [float('%.6f' % (array[0] - toBeAdded)), float('%.6f' % (array[-1] + eachItemShare))]])
			elif i == 0:
				queue.append([prevProb * prob, count + 1, [float('%.6f' % (array[0] - toBeAdded)), float('%.6f' % (array[1] + eachItemShare)), float('%.6f' % (array[-1] + eachItemShare))]])
			else:
				queue.append([prevProb * prob, count + 1, [float('%.6f' % (array[0] + eachItemShare)), float('%.6f' % (array[1] - toBeAdded)), float('%.6f' % (array[-1] + eachItemShare))]])
	answers.append(ans)
T = int(input())
while T:
	(c, m, p, v) = [float(x) for x in input().split()]
	solve(c, m, p, v)
	T -= 1
for ans in answers:
	print(ans)


import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
mod = 100000000
sys.setrecursionlimit(1000000)
try:
	sys.stdin = open('actext.txt', 'r')
	OPENFILE = 1
except:
	pass

def get_ints():
	return map(int, input().split())

def palindrome(s):
	mid = len(s) // 2
	for i in range(mid):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def check(i, n):
	if 0 <= i < n:
		return True
	else:
		return False

def dpsolve(i, c, m, p, v):
	ans = p * i / mod
	flg = 1
	if c > v:
		newc = c - v
		vv = v
	elif c > 0:
		newc = 0
		vv = c
	else:
		flg = 0
	if flg == 1:
		if m > 0:
			newm = m + vv / 2
			newp = p + vv / 2
		else:
			newm = 0
			newp = p + vv
		ans += c / mod * dpsolve(i + 1, newc, newm, newp, v)
	flg = 1
	if m > v:
		newm = m - v
		vv = v
	elif m > 0:
		newm = 0
		vv = m
	else:
		flg = 0
	if flg:
		if c > 0:
			newc = c + vv / 2
			newp = p + vv / 2
		else:
			newc = 0
			newp = p + vv
		ans += m / mod * dpsolve(i + 1, newc, newm, newp, v)
	return ans

def dpsolve2(i, c, m, p, v):
	if c == 0 and m == 0:
		return p / mod * i
	if c == 0:
		if m > v:
			newm = m - v
			newp = p + v
		else:
			newm = 0
			newp = 1
		return m / mod * dpsolve(i + 1, 0, newm, newp, v) + p / mod * i
	if m == 0:
		if c > v:
			newc = c - v
			newp = p + v
		else:
			newc = 0
			newp = 1
		return c / mod * dpsolve(i + 1, newc, 0, newp, v) + p / mod * i
	first = 0
	if c > v:
		newc = c - v
		newm = m + v / 2
		newp = p + v / 2
	else:
		newc = 0
		newm = m + c / 2
		newp = p + c / 2
	first = c / mod * dpsolve(i + 1, newc, newm, newp, v)
	second = 0
	if m > v:
		newm = m - v
		newc = c + v / 2
		newp = p + v / 2
	else:
		newm = 0
		newc = c + m / 2
		newp = p + m / 2
	second = m / mod * dpsolve(i + 1, newc, newm, newp, v)
	return first + second + p / mod * i

def solve(c, m, p, v):
	c = c * mod
	m = m * mod
	p = p * mod
	v = v * mod
	ans = dpsolve(1, c, m, p, v)
	print(ans)
t = int(input())
for tt in range(t):
	(c, m, p, v) = map(float, input().split())
	solve(c, m, p, v)


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import copy, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
from operator import itemgetter

def main():
	(c, m, p, v) = list(map(float, input().split()))
	ans = 0

	def rec(x, y, z, n=1, i=1):
		nonlocal ans, v
		ans += i * n * z
		if x > 1e-08:
			if x >= v:
				if y > 1e-08:
					rec(x - v, y + v / 2, z + v / 2, n + 1, i * x)
				else:
					rec(x - v, 0, z + v, n + 1, i * x)
			elif y > 1e-08:
				rec(0, y + x / 2, z + x / 2, n + 1, i * x)
			else:
				rec(0, 0, z + x, n + 1, i * x)
		if y > 1e-08:
			if y >= v:
				if x > 1e-08:
					rec(x + v / 2, y - v, z + v / 2, n + 1, i * y)
				else:
					rec(0, y - v, z + v, n + 1, i * y)
			elif x > 1e-08:
				rec(x + y / 2, 0, z + y / 2, n + 1, i * y)
			else:
				rec(0, 0, z + y, n + 1, i * y)
	rec(c, m, p)
	print(ans)
for _ in range(II()):
	main()


t = int(input())
for _ in range(t):

	def f(c, m, p, v):
		if c <= v:
			if m > 0:
				return (-1, m + c / 2, p + c / 2, v)
			else:
				return (-1, -1, 10000, v)
		elif m > 0:
			return (c - v, m + v / 2, p + v / 2, v)
		else:
			return (c - v, -1, p + v, v)

	def g(c, m, p, v):
		if m <= v:
			if c > 0:
				return (c + m / 2, -1, p + m / 2, v)
			else:
				return (-1, -1, 10000, v)
		elif c > 0:
			return (c + v / 2, m - v, p + v / 2, v)
		else:
			return (-1, m - v, p + v, v)

	def exp(c, m, p, v):
		if p == 10000:
			return 1
		s = p
		if c > 0:
			s += c * (1 + exp(*f(c, m, p, v)))
		if m > 0:
			s += m * (1 + exp(*g(c, m, p, v)))
		return s / 10000
	(c, m, p, v) = map(float, input().split())
	c *= 10000
	m *= 10000
	p *= 10000
	v *= 10000
	print(exp(c, m, p, v))


import sys
import math
import collections
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]
r = sys.stdin.readline

def f(depth, c, m, p, now):
	global ans
	ans += depth * p * now
	if c <= 1e-08 and m <= 1e-08:
		return
	if c <= 1e-08:
		f(depth + 1, 0, m - min(m, v), p + min(m, v), now * m)
	elif m <= 1e-08:
		f(depth + 1, c - min(c, v), 0, p + min(c, v), now * c)
	else:
		f(depth + 1, c + min(m, v) / 2, m - min(m, v), p + min(m, v) / 2, now * m)
		f(depth + 1, c - min(c, v), m + min(c, v) / 2, p + min(c, v) / 2, now * c)
for _ in range(int(r())):
	(c, m, p, v) = map(float, r().split())
	ans = 0
	f(1, c, m, p, 1)
	print(ans)


import sys
input = sys.stdin.readline

def dfs(c, m, p, Prob, Try):
	Ex = Try * Prob * p
	if c < 1e-07:
		c = 0
	if m < 1e-07:
		m = 0
	if c and m:
		Ex += dfs(max(0, c - V), m + min(c, V) / 2, p + min(c, V) / 2, Prob * c, Try + 1)
		Ex += dfs(c + min(m, V) / 2, max(0, m - V), p + min(m, V) / 2, Prob * m, Try + 1)
	elif c:
		Ex += dfs(max(0, c - V), 0, p + min(c, V), Prob * c, Try + 1)
	elif m:
		Ex += dfs(0, max(0, m - V), p + min(m, V), Prob * m, Try + 1)
	return Ex
T = int(input())
for _ in range(T):
	(C, M, P, V) = map(float, input().split())
	print(dfs(C, M, P, 1, 1))


delta = 1e-12

def recur(a, b, c, d, cur=1):
	assert abs(a + b + c - 1) < delta * 0.1, f'{a} {b} {c}'
	(a, b) = sorted([a, b])
	if a > delta:
		A = recur(max(a - d, 0), b + min(a / 2, d / 2), c + min(a / 2, d / 2), d, cur + 1) * a
	else:
		A = 0
	if b > delta:
		if a > delta:
			B = recur(a + min(b / 2, d / 2), max(b - d, 0), c + min(b / 2, d / 2), d, cur + 1) * b
		else:
			B = recur(a, max(b - d, 0), c + min(b, d), d, cur + 1) * b
	else:
		B = 0
	return A + B + c * cur
for _ in range(int(input())):
	(a, b, c, d) = map(float, input().split())
	print(recur(a, b, c, d))


def help(c, m, p, v, count, h):
	global ans
	if c < 1e-06:
		c = 0
	if m < 1e-06:
		m = 0
	if c == 0 and m == 0:
		ans = ans + p * count * h
		return
	ans = ans + h * p * count
	(x, y, z) = (c, m, p)
	if c != 0:
		if m != 0:
			if c <= v:
				m = m + c / 2
				p = p + c / 2
			else:
				m = m + v / 2
				p = p + v / 2
		elif c <= v:
			p = p + c
		else:
			p = p + v
		c = max(0.0, c - v)
		help(c, m, p, v, count + 1, h * x)
	(c, m, p) = (x, y, z)
	if m != 0:
		if c != 0:
			if m <= v:
				c = c + m / 2
				p = p + m / 2
			else:
				c = c + v / 2
				p = p + v / 2
		elif m <= v:
			p = p + m
		else:
			p = p + v
		m = max(0.0, m - v)
		help(c, m, p, v, count + 1, h * y)
for _ in range(int(input())):
	(c, m, p, v) = map(float, input().split())
	ans = 0
	help(c, m, p, v, 1, 1.0)
	print('%.25f' % ans)


from decimal import *
getcontext().prec = 20
input = __import__('sys').stdin.readline
mis = lambda : map(int, input().split())
ii = lambda : int(input())
dp = {}
v = None

def solve(s):
	if s in dp:
		return dp[s]
	(a, b, c) = s
	ret = (c, c)
	if a > 0:
		na = max(Decimal(0), a - v)
		x = a - na
		nb = b
		nc = c
		if b > 0:
			nb += x / 2
			nc += x / 2
		else:
			nc += x
		nret = solve((na, nb, nc))
		ret = (ret[0] + a * (nret[0] + nret[1]), ret[1] + a * nret[1])
	if b > 0:
		nb = max(Decimal(0), b - v)
		x = b - nb
		na = a
		nc = c
		if a > 0:
			na += x / 2
			nc += x / 2
		else:
			nc += x
		nret = solve((na, nb, nc))
		ret = (ret[0] + b * (nret[0] + nret[1]), ret[1] + b * nret[1])
	dp[s] = ret
	return ret
for tc in range(ii()):
	dp = {}
	(a, b, c, _v) = map(Decimal, input().split())
	v = _v
	print(solve((a, b, c))[0])