﻿ Fuzhou University OnlineJudge ﻿
Problem 1704 Turn off the light

## Problem Description

There are N lights and M switches in Peter’s bedroom. Every switch controls some lights among all. When press the switch, these lights will change their statuses (the lighting ones will be turn off, while the shutting one will be turn on.) Now some lights are lighting. Peter would like to know that under the premises of not pressing one switch twice, how many methods he could turn all the lights off. There is always at least one way to turn all the lights off.

## Input

The first line of the input is an integer T which indicates the number of test cases.
For each test case, the first line are two integers N (1 ≤ N ≤ 100) and M (1 ≤ M ≤ 100).
Second line contains N number indicating that the ith light is on if the ith number is 1, or 0 otherwise.
The ith line of the following M lines contains a number D (1 ≤ D ≤ N) and D numbers, indicating the lights under this switch’s control. Lights are numbered from 1 to N.

## Output

For each test case, print a line contains the answer.

## Sample Input

1 2 3 1 1 2 1 2 1 1 1 2

2

## Source

FOJ-2009年4月月赛 Coral

Submit  Back  Status  Discuss
﻿