Kid is a famous thief and he is known for his unique habit. Before his attempt, he will always inform the person who he is going to rob beforehand. Though the people have paid much attention to him, he has never failed. This time Kid informed a billionaire, Jack, that he is going to enter Jack's home to take away his expensive treasure. Jack is very afraid and he asked a brilliant boy, Conan, to help him. Conan designed a special lock for Jack’s home. However, Kid is very tricky and he stole the structure map and the password of the lock.
There are several test cases. In the first line of each case there are two integers K (1 <= K <= 20) and N (2 <= N <= 10). Then follows a line with K integers expressing the password. Each number in the password is between 1 and N. Then come K lines, the i-th of which describes how the i-th dial plate controls the referred gears. These K lines have the following format:
p a1 b1 a2 b2 ... ap bp
Integer p (0 <= p <= K) expresses the number of gears that are referred to the dial plate. ai (1 <= i <= p) is an integer between 1 and K which tells that the ai-th gear is under the control of this dial plate. bi is an integer between 1 and N-1 which tells that when the dial plate is dialed once, the ai-th gear will rotate across by bi gears.
A test case of K = 0 and N = 0 indicates the end of input, and should not be processed.
For each test case, there is a single line. If the lock can be opened, the line contains the least number of times Kid should dial the dial plates; otherwise, output "No solution".
1 4 2 1 1 2 4 8 8 8 8 8 4 1 1 2 2 4 1 3 1 2 4 7 3 2 2 1 5 3 5 1 2 7 0 0
No solution 2