OI Problems   关于

#361dz8. Fluorescent

时间限制:2 s       空间限制:512 MiB       标签: 数学 概率期望 动态规划 状态压缩动态规划 ICPC 北京 2014 缺题解 

算法难度等级:0       思维难度等级:0       实现难度等级:0


本题来源于:2014 年 ACM/ICPC 亚洲区北京站

  • 简体中文
  • English

nn 个灯,mm 个开关,每个开关能控制一些灯的状态,即关闭的打开,打开的关闭。一开始灯全部是关闭的。现在有个人去操作这些开关,显然会有 2m2^m 次组合。现在问这个人操作完这些开关后,亮着的灯的期望 E(x)E(x)。但是题目要求输出的是 E(X3)2m mod (109+7)E(X^3)\cdot 2^m\text{ mod }(10^9+7)

Input

The first line contains only one integer TT, which indicates the number of test cases.

For each test case, the first line contains N,MN, M (1N,M501 \leq N, M \leq 50), denoting the number of fluorescent lights (numbered from 11 to NN) and the number of switches (numbered from 11 to MM).

MM lines follow. The ii-th line begins with an integer KiK_i (1KiN1\leq K_i\leq N). KiK_i distinct integers li,jl_{i,j} (1li,jN1 \leq l_{i,j} \leq N) follow, denoting the fluorescent lights that the ii-th switch controls.

Output

For each test case, output a single line Case #x: y, where xx is the case number (starting from 11) and yy is the answer. To avoid rounding error, the answer you should output is:

E(X3)2M mod (109+7).E(X^3)\cdot 2^M\text{ mod }(10^9+7).

Sample

2
2 2
1 1
2 1 2
3 1
3 1 2 3
Case #1: 10
Case #2: 27

Hint

For the first sample, there’re 44 possible situations:

All the switches is off, no light is bright, X3=0X^3 = 0.

Only the first switch is on, the first light is bright, X3=1X^3 = 1.

Only the second switch is on, all the lights are bright, X3=8X^3 = 8.

All the switches is on, the second lights are bright, X3=1X^3 = 1.

Therefore, the answer is E(X3)22 mod (109+7)=10E(X^3) \cdot 2^2\text{ mod }(10^9 + 7) = 10.

For the second sample, there’re 22 possible situations:

The switches is off, no light is bright, X3=0X^3 = 0.

The switches is on, all the lights are bright, X3=27X^3 = 27.

Therefore, the answer is E(X3)21 mod (109+7)=27E(X^3) \cdot 2^1\text{ mod }(10^9 + 7) = 27.

Matt, a famous adventurer who once defeated a pack of dire wolves alone, found a lost court. Matt finds that there are NN fluorescent lights which seem to be the stars from the firmament. What’s more, there are MM switches that control these fluorescent lights. Each switch is connected to a group of lights. When Matt touches a switch, all the lights connected to it will change their states (turning the dark on, turning the bright off).

Initially, all the fluorescent lights are dark. For each switch, Matt will touch it with probability 11.

As a curious gentleman, Matt wants to calculate E(X3)E(X^3), where X represents the number of bright lights at the end, E(X3)E(X^3) represents the expectation of cube of XX.

Input

The first line contains only one integer TT, which indicates the number of test cases.

For each test case, the first line contains N,MN, M (1N,M501 \leq N, M \leq 50), denoting the number of fluorescent lights (numbered from 11 to NN) and the number of switches (numbered from 11 to MM).

MM lines follow. The ii-th line begins with an integer KiK_i (1KiN1\leq K_i\leq N). KiK_i distinct integers li,jl_{i,j} (1li,jN1 \leq l_{i,j} \leq N) follow, denoting the fluorescent lights that the ii-th switch controls.

Output

For each test case, output a single line Case #x: y, where xx is the case number (starting from 11) and yy is the answer. To avoid rounding error, the answer you should output is:

E(X3)2M mod (109+7).E(X^3)\cdot 2^M\text{ mod }(10^9+7).

Sample

2
2 2
1 1
2 1 2
3 1
3 1 2 3
Case #1: 10
Case #2: 27

Hint

For the first sample, there’re 44 possible situations:

All the switches is off, no light is bright, X3=0X^3 = 0.

Only the first switch is on, the first light is bright, X3=1X^3 = 1.

Only the second switch is on, all the lights are bright, X3=8X^3 = 8.

All the switches is on, the second lights are bright, X3=1X^3 = 1.

Therefore, the answer is E(X3)22 mod (109+7)=10E(X^3) \cdot 2^2\text{ mod }(10^9 + 7) = 10.

For the second sample, there’re 22 possible situations:

The switches is off, no light is bright, X3=0X^3 = 0.

The switches is on, all the lights are bright, X3=27X^3 = 27.

Therefore, the answer is E(X3)21 mod (109+7)=27E(X^3) \cdot 2^1\text{ mod }(10^9 + 7) = 27.