Equalization

All submissions for this problem are available.
Bob has an array consisting of N integers. He wants to perform a sequence of operations after which all the numbers in the array will be equal.
Each operation consists of choosing any prime integer P. Bob then chooses any P numbers from the array and replaces each of them by the arithmetic mean of these P numbers (leaving them at the same places in the array as before this operation). Note that the resulting numbers may not be integer.
Help Bob, find a sequence of operations which achieves his goal. It is guaranteed that this goal is always achievable. The sequence is not required to be the shortest, but it should consist of no more than 1000 operations.
Input
The first line of the input contains a single integer T, the number of test cases (no more than 20). Each test case is described by two lines. The first line contains a single integer N (2 ≤ N ≤ 30). The second line contains N integers A_{i} (1 ≤ A_{i} ≤ 1000) separated by single spaces.
Output
For each test case output a line containing a single integer K (0 ≤ K ≤ 1000), the number of operations in your sequence, followed by K lines describing the operations in the order of execution. In the i^{th} of these lines, print a prime integer P_{i} (2 ≤ P_{i} ≤ N) followed by P_{i} distinct spaceseparated integers B_{i, j} (1 ≤ B_{i, j} ≤ N), the 1based indices of the elements in the array which are chosen for this operation. See the Example Section below for clarity.
Example
Input: 6 4 5 6 7 8 7 9 5 4 9 4 2 11 6 42 42 42 42 42 42 6 9 1 8 2 7 3 12 7 2 6 9 3 9 11 2 5 1 4 13 9 12 10 5 14 16 3 2 1 9 Output: 2 2 2 3 2 1 4 1 7 3 1 7 4 6 2 5 0 5 3 1 2 3 3 4 5 6 2 1 4 2 2 5 2 3 6 16 3 1 2 3 3 4 5 6 2 1 4 2 2 5 2 3 6 3 7 8 9 3 10 11 12 2 7 10 2 8 11 2 9 12 2 1 7 2 2 8 2 3 9 2 4 10 2 5 11 2 6 12 6 3 1 2 3 3 4 5 6 3 7 8 9 3 1 4 7 3 2 5 8 3 3 6 9
Explanation
In the first test case, the initial array is (5, 6, 7, 8). The array after the first operation is (5, 6.5, 6.5, 8). The array after the second operation is (6.5, 6.5, 6.5, 6.5).
In the second test case, all the elements of the array become equal to 44/7 after the only operation.
In the third test case, all the elements of the array are already equal, so no operations are needed.
In the last test case, after the first 3 operations the array becomes (9, 9, 9, 11, 11, 11, 4, 4, 4). After all the operations are complete, the array looks like (8, 8, 8, 8, 8, 8, 8, 8, 8).
Author:  gennady.korotkevich 
Tester:  gamabunta 
Tags  cook27, gennady.korotkevich, simplemath 
Date Added:  4102012 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYP3 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 