Hide

Problem M
Brass Section

You have been toiling for months over composing the perfect musical score for an upcoming event. All that is left is to plan the grand finale to your opus. You want it to be loud.

The brass section is always eager to blow with all their might! But some temperance is in order, you do not want the audience’s final impressions to be that it was just a cacaphony of noise. So you will ask some instruments to play quietly. To determine which ones should play quietly, you organize the musicians playing brass instruments into groups: a musician may be a member of multiple groups or perhaps none at all.

For each member of each group, you have a preference for them to play quietly or loudly. It might be that a member is preferred to play loudly in one group and quietly in another group.

Your task is to determine if it is possible to tell each musician how to play (quietly or loudly) such that within each group, at least one preference in that group is satisfied. Of course, if it is possible then you want to maximize the number of musicians that play loudly.

Oh, one more thing. At most one member from each group will be preferred to play quietly. After all, you want a loud grand finale.

Input

The first line of input contains two integers $N$ ($1 \leq N \leq 200\, 000$) and $G$ ($1 \leq G \leq 200\, 000$). Here, $N$ is the number of musicians in the brass section and $G$ is the number of groups.

The next $G$ lines each describe a group’s requirements. Each such line begins with an integer $K$ ($1 \leq K \leq N$) giving the number of members of that group. The rest of the line consists of $K$ integers $x_1, x_2, \ldots , x_K$ where each $x_i$ is a nonzero integer satisfying $-N \leq x_i \leq N$. Furthermore, the absolute values of these integers are distinct (i.e. each musician is represented in this group at most once) and at most one of these integers will be negative.

In any such line, $x_i$ being positive indicates that the group’s preference for $x_i$ is that they play loudly. Similarly, $x_i$ being negative indicates that the group’s preference for $|x_i|$ is that they play quietly.

Finally, the total size of all groups will be at most $400\, 000$.

Output

If it is possible to satisfy at least one preference from each group, first output a line with the text possible and then output a second line containing a single string (no spaces) consisting of characters Q and L. The $i$’th character in this line indicates if musician $i$ should play quietly (Q) or loudly (L). These instructions should satisfy at least one preference from each group. This line should also have the maximum number of L characters among all valid solutions (any valid solution with the maximum number of L characters will be accepted).

If it is not possible to satisfy at least one preference from each group, output just a single line with the text impossible (no second line should be output in this case).

Sample Input 1 Sample Output 1
4 3
2 1 2
1 -1
3 3 -2 4
possible
QLLL
Sample Input 2 Sample Output 2
4 4
2 1 2
1 -1
2 4 -2
1 -4
impossible

Please log in to submit a solution to this problem

Log in