#ARRHUDAI. Array with Hudai Calculation

Array with Hudai Calculation

当前没有测试数据。

Array with Hudai Calculation

You will be given an array A with N integers A[1…N]. You will also be given two integers P and K. You need to find a value X [ X can be any value from array A] for which this function will be maximized:

 formula

Here ABS means Absolute Value. For example: ABS(-1) is 1, also ABS(1) means 1.

Here MOD means Modulo Operation.  W MOD Y will give you the remainder after dividing W by Y.

And X is any value from the array A.

But we don’t have interest in X, as there will be several X for which the value will be maximized. So we just want the maximum value. Can you find it for us as you are a great programmer on SPOJ ?

Input

Input starts with an integer T (≤ 5), denoting the number of test cases.

Each case starts with a line containing three integers N, P and K. Then the next line will be consisting of N integers.

1 <= N <= 100000

1 <= P <= 100

1 <= K <= 1000000009

1 <= A[i] <= 2000

Output

For each case, print the case number and the maximum value for the above function with respect to array A.

Sample Input

Output for Sample Input

2

3 1 10

3 1 2

3 2 10

3 1 2

 

Case 1: 3

Case 2: 5

 

N.B: Dataset is huge. Use faster IO like Scanf , Printf