#Lutece0569. Color II
Color II
Migrated from Lutece 569 Color II
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
ZT loves to paint on papers. One day, he wants to paint every cell on the board whose size is with black and white. However, the painted board should meet this condition: for every block, there are exactly white cells and black cells. To make this problem more interesting, some cells on board have already been colored. How many different boards can ZT paint?
Note that two boards are different if at least one corresponding cell's color is different.
Input
There are multiple test cases. The first line of the input will be an integer () indicating the number of test cases.
For each test case there are three integers , , (, ) in a single line, representing the size of board and the number of colored cells. For the following lines, each line contains two integers , and a character . It means the cell in the row and column has been colored in . , , is W
or B
indicating this cell is colored in white or black.
Output
For each test case, print Case #t:
first, in which is the number of the test case starting from . Then output five integers indicating the number of different colored boards when . The result should be modulo by .
Samples
1
3 3 2
1 1 B
2 2 W
Case #1: 0 1 4 3 0
Note
The first sample is like this
B..
.W.
...
Resources
10th UESTC Programming Contest Final