gCube (Large)

Answer many range queries asking for the geometric mean of array values with nine digits after the decimal point.

Medium5Prefix sumMathNo attempts yetTime limit5sMemory limit512 MB

Problem

A DD-dimensional cube has DD dimensions whose lengths are all equal. DD may be any positive integer, so a 1-dimensional cube is a line segment, a 2-dimensional cube is a square, and a 4-dimensional cube is a hypercube. A DD-dimensional cuboid also has DD dimensions, but their lengths may differ.

You are given one NN-dimensional cuboid. Its dimensions are numbered 0,1,,N10, 1, \dots, N-1 in order, and dimension ii has length aia_i. Solve MM subproblems of the following form.

  1. Take every dimension from dimension LiL_i to dimension RiR_i, inclusive.
  2. Use those dimensions to form a DD-dimensional cuboid, where D=RiLi+1D = R_i - L_i + 1. For example, if Li=3L_i = 3 and Ri=6R_i = 6, you form a 4-dimensional cuboid from dimensions 3, 4, 5, and 6.
  3. Reshape it into a DD-dimensional cube with exactly the same volume, and find the edge length of that cube.

All MM subproblems of one test case use the same NN-dimensional cuboid.

Input

The first line has the number of test cases TT. Then TT test cases follow.

The first line of each test case has the number of dimensions NN and the number of queries MM. The next line has the lengths of the dimensions a0,a1,,aN1a_0, a_1, \dots, a_{N-1} in order. Of the MM lines that follow, line ii has the range LiL_i and RiR_i of dimensions that the ii-th subproblem uses.

Output

For each test case, first print one line of the form Case #x:, where xx is the test case number starting at 1. Then print MM lines; line ii has the edge length of the ii-th subproblem, written with exactly nine digits after the decimal point. Round at the tenth digit after the decimal point.

The edge length is the DD-th root of aLi××aRia_{L_i} \times \cdots \times a_{R_i}. That value is usually irrational and reaches 10910^9 in size, so double precision floating point alone does not give nine correct digits.

Constraints

  • 1T1001 \le T \le 100
  • 1N10001 \le N \le 1000
  • 1M1001 \le M \le 100
  • 1ai1091 \le a_i \le 10^9
  • 0LiRi<N0 \le L_i \le R_i < N