Hedgemony (Large)

Simulate one left-to-right pass that trims each bush to the average of its neighbors when taller, then report the final height of bush N-1 with six decimals.

Easy3SimulationMathInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Baron Cohen keeps a hedge of NN bushes planted side by side in one straight line. The bushes are numbered 1 to NN from left to right, and the height of bush ii is an integer. His neighbours trim their hedges so that every bush ends up at the same height. The baron's gardener follows a different rule.

The rule is this. The gardener starts at bush 2 and moves right, visiting bushes 2,3,,N12, 3, \dots, N-1 in that order. Standing at bush ii, he takes the average of the current heights of bush i1i-1 and bush i+1i+1. If bush ii is taller than that average, he cuts its top so that its height becomes exactly the average. If bush ii is already at the average or below it, he leaves that bush alone and moves on to the bush on its right. He never walks back, so the height he uses for bush i1i-1 is the height it has after its own trim.

Find the height of bush N1N-1 after the gardener finishes.

Input

The first line contains the number of test cases TT. Each test case follows on two lines. The first line contains an integer NN. The second line contains NN space-separated integers, the heights of bush 1 through bush NN.

Limits

  • 1T1001 \le T \le 100
  • 3N10003 \le N \le 1000
  • Every height is an integer between 1 and 1000, inclusive.

Output

For each test case, print one line in the form Case #x: y, where xx is the case number starting from 1 and yy is the height of bush N1N-1 after the gardener has finished. Print yy with exactly six digits after the decimal point, rounded to the nearest value that six digits can express. No input is given whose answer lies exactly halfway between two such values.