Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

meet-in-the-middle

*2600

No tag edit access

The problem statement has recently been changed. View the changes.

×
L. Light switches

time limit per test

3 secondsmemory limit per test

1024 megabytesinput

standard inputoutput

standard outputNikola owns a large warehouse which is illuminated by $$$N$$$ light bulbs, numbered $$$1$$$ to $$$N$$$. At the exit of the warehouse, there are $$$S$$$ light switches, numbered $$$1$$$ to $$$S$$$. Each switch swaps the on/off state for some light bulbs, so if a light bulb is off, flipping the switch turns it on, and if the light bulb is on, flipping the switch turns it off.

At the end of the day, Nikola wants to turn all the lights off. To achieve this, he will flip some of the light switches at the exit of the warehouse, but since Nikola is lazy, he wants to flip the _minimum_ number of switches required to turn all the lights off. Since Nikola was not able to calculate the minimum number of switches, he asked you to help him. During a period of $$$D$$$ days, Nikola noted which light bulbs were off and which were on at the end of each day. He wants you to tell him the minimum number of switches he needed to flip to turn all the lights off for each of the $$$D$$$ days or tell him that it's impossible.

Input

First line contains three integers, $$$N$$$, $$$S$$$ and $$$D$$$ ($$$1 \leq N \leq 10^3$$$, $$$1 \leq S \leq 30$$$, $$$1 \leq D \leq 10^3$$$) – representing number of light bulbs, the number of light switches, and the number of days respectively.

The next $$$S$$$ lines contain the description of each light switch as follows: The first number in the line, $$$C_i$$$ ($$$1 \leq C_i \leq N$$$), represents the number of light bulbs for which the on/off state is swapped by light switch $$$i$$$, the next $$$C_i$$$ numbers (sorted in increasing order) represent the indices of those light bulbs.

The next $$$D$$$ lines contain the description of light bulbs for each day as follows: The first number in the line, $$$T_i$$$ ($$$1 \leq T_i \leq N$$$), represents the number of light bulbs which are on at the end of day $$$i$$$, the next $$$T_i$$$ numbers (sorted in increasing order) represent the indices of those light bulbs.

Output

Print $$$D$$$ lines, one for each day. In the $$$i^{th}$$$ line, print the minimum number of switches that need to be flipped on day $$$i$$$, or $$$-1$$$ if it's impossible to turn all the lights off.

Example

Input

4 3 4 2 1 2 2 2 3 1 2 1 1 2 1 3 3 1 2 3 3 1 2 4

Output

2 2 3 -1

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/23/2024 03:45:31 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|