Milkshakes (Small)

Assign each flavor malted or unmalted so every customer gets a liked type, minimizing malted batches, with at most one malted liked type per customer.

Medium5GreedyImplementationBrute forceMathInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

You run a milkshake shop. You can prepare NN different flavors, and each flavor can be prepared malted or unmalted, so there are 2N2N different types of milkshake.

Each customer has a set of milkshake types they like, and a customer is satisfied if you have prepared at least one type from that set. At most one of the types a customer likes is malted.

You want to make NN batches of milkshakes so that all of the following hold.

  • There is exactly one batch for each flavor, and that batch is either malted or unmalted.
  • For each customer, you make at least one type that the customer likes.
  • The number of malted batches is as small as possible.

Decide whether you can satisfy every customer, and if you can, find which types you should make.

When every customer can be satisfied, the assignment that minimizes the number of malted batches is unique.

Input

The first line contains the number of test cases CC.

Each test case is given as follows.

  • The first line contains the number of milkshake flavors NN.
  • The second line contains the number of customers MM.
  • Each of the next MM lines describes one customer. The line starts with the number of types that customer likes, TT, followed by TT integer pairs X YX\ Y. Here XX is a flavor number between 11 and NN, and YY is 00 for unmalted or 11 for malted.

All numbers on a line are separated by single spaces.

Limits

  • 1C1001 \le C \le 100
  • 1N101 \le N \le 10
  • 1M1001 \le M \le 100
  • T1T \ge 1
  • Within one customer, the same pair (X,Y)(X, Y) never appears twice.
  • Among the types one customer likes, at most one pair has Y=1Y = 1.

Output

Print CC lines, one per test case, in the order the test cases are given. Each line starts with Case #X: , where XX is the test case number starting from 11. After that prefix, print the following.

  • Print IMPOSSIBLE if the customers' preferences cannot all be satisfied.
  • Otherwise print NN integers separated by spaces, one for each flavor from 11 to NN. The integer is 00 if that flavor should be prepared unmalted and 11 if it should be prepared malted.

Hint

In the first test case of the first example, flavor 11 must be malted to satisfy the first customer. Every other flavor can be unmalted. The second customer is satisfied by unmalted flavor 22, and the third customer is satisfied by unmalted flavor 55.

The second test case has only one flavor. One customer likes it malted and the other likes it unmalted, so you cannot satisfy both.