#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 N×MN \times M with black and white. However, the painted board should meet this condition: for every 2×22 \times 2 block, there are exactly WW white cells and 4W4 - W 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 TT (T50T\leq 50) indicating the number of test cases.

For each test case there are three integers NN, MM, KK (2N,M1000002 \leq N, M \leq 100000, 0K1000000 \leq K \leq 100000) in a single line, representing the size of board and the number of colored cells. For the following KK lines, each line contains two integers RiR_i, CiC_i and a character SiS_i. It means the cell in the RithR_i^{th} row and CithC_i^{th} column has been colored in SiS_i. 1RiN1 \leq R_i \leq N, 1CiM1 \leq C_i \leq M, SiS_i is W or B indicating this cell is colored in white or black.

Output

For each test case, print Case #t: first, in which tt is the number of the test case starting from 11. Then output five integers indicating the number of different colored boards when W=0,W=1,W=2,W=3,W=4W = 0, W = 1, W = 2, W = 3, W = 4. The result should be modulo by 2012040720120407.

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