Problem: Turtle Alice is currently designing a fortune cookie box, and she would like to incorporate the theory of LuoShu into it.
The box can be seen as an grid (), where the rows are numbered and columns are numbered . Each cell can either be empty or have a single fortune cookie of one of the following shapes: circle or square. The cell at the intersection of the -th row and the -th column is denoted as .
Initially, the entire grid is empty. Then, Alice performs operations on the fortune cookie box. The -th operation () is as follows: specify a currently empty cell and a shape (circle or square), then put a fortune cookie of the specified shape on cell . Note that after the -th operation, the cell is no longer empty.
Before all operations and after each of the operations, Alice wonders what the number of ways to place fortune cookies in all remaining empty cells is, such that the following condition is satisfied:
No three consecutive cells (in horizontal, vertical, and both diagonal directions) contain cookies of the same shape. Formally:
- There does not exist any satisfying , such that there are cookies of the same shape in cells .
- There does not exist any satisfying , such that there are cookies of the same shape in cells .
- There does not exist any satisfying , such that there are cookies of the same shape in cells .
- There does not exist any satisfying , such that there are cookies of the same shape in cells .
You should output all answers modulo . Also note that it is possible that after some operations, the condition is already not satisfied with the already placed candies, in this case you should output .
Input Format: The first line of the input contains a single integer () — the number of test cases.
The first line of each test case contains three integers , , ().
The -th of the next lines contains two integers , and a single string (, "circle" or "square"), representing the operations. It is guaranteed that the cell on the -th row and the -th column is initially empty. That means, each will appear at most once in the updates.
The sum of over all test cases does not exceed .
Output Format: For each test case, output lines. The first line of each test case should contain the answer before any operations. The -th line () should contain the answer after the first operations. All answers should be taken modulo .
Note: In the second sample, after placing a circle-shaped fortune cookie to cells , and , the condition is already not satisfied. Therefore, you should output .