A tail-hedge book bleeds by design. Its NAV starts at X_0 = 1 and follows the disclosed model: each day, independently of the past,
X_{t+1} = X_t * U with probability p
X_{t+1} = X_t * d with probability 1 - p
where 0 < d < 1 < U. The values d and U are given for every case; p is chosen so that the NAV is a martingale.
For each case you see the daily history X_1 .. X_N and a horizon h. Output two numbers: m = E[X_{N+h} | history] and q = P(X_{N+h} > X_N).
The first line contains the integer T, the number of cases. Each case consists of two lines: a line d U h N (d with 4 decimals, U with 2 decimals, h and N integers), and a line with the N reals X_1 .. X_N.
T lines. Line i: m q for case i, separated by a space.
1 <= T <= 200
0.96 <= d <= 0.999
2 <= U <= 40
20 <= h <= 500
100 <= N <= 400
This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.
Numeric answers are accepted if they are within an absolute tolerance of 1e-12 or a relative tolerance of 1e-09 of the expected value.