# Code Feat

Hooray! Agent Bauer has shot the terrorists, blown up the bad guy base, saved the hostages, exposed the moles in the government, prevented an environmental catastrophe, and found homes for three orphaned kittens, all in the span of 19 consecutive hours. But now, he only has 5 hours remaining to deal with his final challenge: an activated nuclear bomb protected by a security code. Can you help him figure out the code and deactivate it? Events occur in real time. The government hackers at CTU (Counter-Terrorist Unit) have learned some things about the code, but they still haven’t quite solved it. They know it’s a single, strictly positive, integer. They also know several clues of the form “when divided by X, the remainder is one of {Y1, Y2, Y3, . . . , Yk}”. There are multiple solutions to these clues, but the code is likely to be one of the smallest ones. So they’d like you to print out the first few solutions, in increasing order. The world is counting on you! Input Input consists of several test cases. Each test case starts with a line containing C, the number of clues (1 ≤ C ≤ 9), and S, the number of desired solutions (1 ≤ S ≤ 10). The next C lines each start with two integers X (2 ≤ X) and k (1 ≤ k ≤ 100), followed by the k distinct integers Y1, Y2, ..., Yk (0 ≤ Y1,Y2,...,Yk < X). You may assume that the X’s in each test case are pairwise relatively prime (ie, they have no common factor except 1). Also, the product of the X’s will fit into a 32-bit integer. The last test case is followed by a line containing two zeros. Output For each test case, output S lines containing the S smallest positive solutions to the clues, in increasing order. Print a blank line after the output for each test case. Sample Input 32 211 5203 3212 00 Sample Output 5 13