Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 3482
For Loop

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Here is a chunk of C code:

 1 enum {
 2     BASE = 1000000007,
 3 };
 4
 5 int a[N] = {2, 3, 5, 7, 11};
 6 int b[M] = {0, 1, 2, 3, 4};
 7 int c[L];
 8
 9 /* recursively gao */
10 void gao(int k) {
11     int i;
12     if (k-- == 0) {
13         /* increase the counter by one*/
14         for (i = 0; ; ++i) {
15             if (++c[i] < BASE) {
16                 break;
17             } else {
18                 c[i] = 0;
19             }
20         }
21     } else {
22         /* the for loop */
23         for (i = a[b[k]]; i < a[b[k + 1]]; ++i) {
24             gao(k);
25         }
26     }
27 }

In this chunk of code, N, M and BASE are all given positive integers, and L is a sufficiently large integer. The array a is a given array of integers, and you can fill the array b with any nonnegative integers less than N as you wish. Your goal is to make the counter c, represented by an array of integers, as large as possible by calling the function gao(M - 1). You should output the lexicographically minimum b to achieve this goal, and output the corresponding value of c[0] as well.

Input

There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.

There are 3 positive integers -- N, M ≤ 100 and 2 ≤ BASE ≤ 1000000007 in the first line of each test case. The second line contains exactly N integers -10000 ≤ ai ≤ 10000.

Output

For each test case, first output the value of c[0], then output the lexicographically minimum b. See sample for more details.

Sample Input

3
5 5 1000000007
2 3 5 7 11
5 3 1000000007
2 3 5 7 11
4 2 1000000007
1 10 100 1000

Sample Output

16
0 1 2 3 4
20
0 3 4
999
0 3

Author: WU, Zejun
Contest: The 11th Zhejiang University Programming Contest
Submit    Status