The Problem with the Problem Setter

The number of students interested to participate in this year’s Intra-BUET Programming Contest is huge. Since it is very difficult to accommodate such a large number of students in our labs, we have decided to arrange a Screening Test. The test will be paper-based and may include as many as 100 analytical problems from as many as 20 categories. I have been assigned the job of setting problems for this test. At first, the job seemed to be very easy since I was told that I would be provided with a pool of about 1000 analytical problems already divided into appropriate categories. But after getting the problems I discovered that for many problems the original authors were not sure about the appropriate categories and so they wrote down multiple category-names in the category fields. Since in the Screening Test a problem cannot be placed under more than one category and the number of problems to be set under each category is fixed, setting problems for this test is not actually easy. I know that a program can be written that can do the job automatically. But since I don’t like writing programs, I seek your help. Input The input file may contain multiple test cases. Each test case begins with a line containing two integers: nk and np (2 ≤ nk ≤ 20,nk ≤ np ≤ 1000) where nk is the number of categories and np is the number of problems in the pool. The second line contains nk positive integers where the i-th integer specifies the number of problems to be included in category i (1 ≤ i ≤ nk) of the test. You may assume that the sum of these nk integers will never exceed 100. The j-th (1 ≤ j ≤ np) of the next np lines contains the category information of the j-th problem in the pool. A category specification for a problem start with a positive integer not greater than nk, specifying the number of categories in one of which this problem can be included, followed by the category numbers. Category numbers are positive integers not greater than nk. A test case containing two zeros for nk and np terminates the input. Output For each test case in the input print a line containing either ‘1’ or ‘0’ depending on whether or not problems can be successfully selected form the pool under the given restrictions (1 for success and 0 for failure). In case of successful selection print nk additional lines where the i-th (1 ≤ i ≤ nk) of these lines contains the problem numbers that can be included in category i. Problem numbers are positive integers not greater then np and two problem numbers must be separated by a single space character. Note that, in case of successful selection any valid selection will be accepted. Sample Input 3 15 334 212 13 13 13 13 3123

2/2 223 213 12 12 212 213 212 11 3123 3 15 734 212 11 12 12 13 3123223 223 12 12 223 223 212 11 3123 00 Sample Output 1 8 11 12 167 2345 0