Hooray! Agent Bauer has shot the terrorists, blown up the bad guy base, saved the
hostages, exposedthe moles in the government, prevented an environmental catastrophe,
and found homes for threeorphaned kittens, all in the span of 19 consecutive hours. But
now, he only has 5 hours remaining todeal with his nal challenge: an activated nuclear
bomb protected by a security code. Can you helphim gure out the code and deactivate
it? Events occur in real time.
he 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 offY1;Y2;Y3;..;Yk"There aremultiple solutions to these clues,but
the code is likely to be one of the smallest ones. So they'd likeyou to print out
the rst 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 Xs in each test case are pairwise relatively prime (ie, they
have no common factor except 1). Also, the product of the Xs 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.