#P9891. List Reshape

List Reshape

List Reshape

Problem Description

ProtectEMmm is learning to use NumPy. She is curious about reshape function, and wants to implement it by hand. For simplicity, hers reshape function reads a non-nested list (which means, all elements in the list are numbers, not a list), and the size of two dimensions of the output list, and then output a 2-dimension list with the data, the order and the number of elements unchanged, but with the specified shape. A well-formatted Python list can be written as a list of comma-separated values (items) between square brackets []. See the sample input and output for more information. The size of each dimensions describes the shape of the list. A x×yx \times y list consists of xx lists, each of which consists of yy numbers. For example, a 2×32 \times 3 list like [[1, 2, 3], [4, 5, 6]], consists of two lists, each of which consists of three numbers. ProtectEMmm finished implementing it quickly. Could you implement it as fast as she can?

Input

The first line contains a integer TT (1T501 \leq T \leq 50), indicating the number of test cases. In each test case: The first line contains a string ss, indicating the list in Python. It is guaranteed that ss is not an empty list. That is, ss is not equal to []. The second line contains two numbers x,yx, y, the size of each dimension of the output list. Your output list need to consist of xx lists, each of which consists of yy numbers. It is guaranteed that the number of elements in ss equals to xyx \cdot y, all elements in the list have no leading zeros, and are in the range 0 to 1000, and the sum of the number of elements in all test cases does not exceed 5×1055 \times 10^5. (请不要使用 scanf 进行读入)

Output

For each test case, you should print a line of string, the result of your reshape operation. Note that you need to print exactly one space between every comma and next item in your output.

Sample Input

4
[3, 1, 4, 1, 5, 9, 2, 6]
2 4
[998, 244, 3, 5, 3]
5 1
[1, 1, 2, 3, 5, 8, 13, 21, 34]
1 9
[2, 3, 5, 7, 11, 13, 17, 19, 23]
3 3

Sample Output

[[3, 1, 4, 1], [5, 9, 2, 6]]
[[998], [244], [3], [5], [3]]
[[1, 1, 2, 3, 5, 8, 13, 21, 34]]
[[2, 3, 5], [7, 11, 13], [17, 19, 23]]

Source

2023“钉耙编程”中国大学生算法设计超级联赛(9)