#H2026B. Be the One

Be the One

Description

Larutan gives Natural a multiset of nn positive integers. A multiset may contain multiple occurrences of the same value.

Natural may perform either of the following operations any number of times:

  1. If the multiset contains at least two occurrences of a value xx, delete one occurrence of xx. This operation costs xx units of time.
  2. Choose one occurrence of a value xx and replace it with x\lfloor\sqrt{x}\rfloor. This operation costs CC units of time.

Values produced by the second operation are also part of the multiset and may be used in subsequent operations.

Determine the minimum total time required to reduce the multiset to exactly one remaining element.

Input Format

The first line contains one integer TT, the number of test cases.

Each test case consists of two lines:

  • The first line contains three integers nn, VV, and CC, where nn is the number of elements, VV is an upper bound on their values, and CC is the cost of one replacement operation.
  • The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n, representing the initial multiset.

Output Format

For each test case, output the minimum total time on a separate line.

Sample

Input #1

1
5 10 3
1 1 3 5 5

Output #1

17

Sample Explanation

Consider the initial multiset {1,1,3,5,5}\{1,1,3,5,5\}.

Perform the following operations:

  1. Delete one occurrence of 55. The multiset becomes {1,1,3,5}\{1,1,3,5\}, at a cost of 55.
  2. Replace 55 with 5=2\lfloor\sqrt{5}\rfloor=2. The multiset becomes {1,1,2,3}\{1,1,2,3\}, at a cost of 33.
  3. Replace 33 with 3=1\lfloor\sqrt{3}\rfloor=1. The multiset becomes {1,1,1,2}\{1,1,1,2\}, at a cost of 33.
  4. Replace 22 with 2=1\lfloor\sqrt{2}\rfloor=1. The multiset becomes {1,1,1,1}\{1,1,1,1\}, at a cost of 33.
  5. Delete one occurrence of 11. The multiset becomes {1,1,1}\{1,1,1\}, at a cost of 11.
  6. Delete one occurrence of 11. The multiset becomes {1,1}\{1,1\}, at a cost of 11.
  7. Delete one occurrence of 11. The multiset becomes {1}\{1\}, at a cost of 11.

The total cost is 5+3+3+3+1+1+1=175+3+3+3+1+1+1=17, which is the minimum possible cost.

Constraints

For all test cases:

  • 1T51\leq T\leq 5;
  • 1n1\leq n and the sum of nn over all test cases does not exceed 10310^3;
  • 1aiV1\leq a_i\leq V;
  • 1V10121\leq V\leq 10^{12};
  • 1C10101\leq C\leq 10^{10}.