Alice is given a list of integers by Bob and is asked to generate a new list where each element in the new list is the sum of some other integers in the original list. The task is slightly more involved, as Bob also asks Alice to repeat this several times before giving him the result. Help Alice automate her task. Input The first line of the input is t (1 ≤ t ≤ 10), the number of cases to follow. Each case is in the following format: nr a0 a1 ... an−1 x0 b0,0 b0,1 . . . x1 b1,0 b1,1 . . . . b0,x0 −1 b1,x1 −1 xn−1 bn−1,0 bn−1,1 . . . bn−1,xn−1 −1 Each case begins with the integer n (1 ≤ n ≤ 50), which is the number of elements in the list of integers that Alice is given. The integer r (1 ≤ r ≤ 109) is the number of times these operations are to be repeated on a list before returning the result. The values are the nonnegative integers in the original list. Then n lines follow that define how Alice will generate a new list from a previous one. Each of these lines are in the form: xi bi,0 bi,1 . . . b1,xi This line defines the value of the i-th element in the new list to be the sum of elements: abi,0,abi,1,...,ab1,xi−1 Output The output consists of t lines, one line for each test case listing the final list of integers modulo 1000 in the form: c0 c1 ... cn−1 Sample Input 2 22 12 201 11 24 507 692 201 11
2/2 Sample Output 52 275 692