Problem: While searching for the pizza, baby Hosssam came across two permutations and of length .
Recall that a permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
Baby Hosssam forgot about the pizza and started playing around with the two permutations. While he was playing with them, some elements of the first permutation got mixed up with some elements of the second permutation, and to his surprise those elements also formed a permutation of size .
Specifically, he mixed up the permutations to form a new array in the following way.
- For each (), he either made or .
- The array is a permutation.
You know permutations , , and values at some positions in . Please count the number different permutations that are consistent with the described process and the given values. Since the answer can be large, print it modulo .
It is guaranteed that there exists at least one permutation that satisfies all the requirements.
Input Format: The first line contains an integer () — the number of test cases.
The first line of each test case contains a single integer () — the length of the permutations.
The next line contains distinct integers () — the first permutation.
The next line contains distinct integers () — the second permutation.
The next line contains distinct integers ( is either , , or ) — the description of the known values of . If , then there are no requirements on the value of . Otherwise, it is required that .
It is guaranteed that there exists at least one permutation that satisfies all the requirements.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format: For each test case, print the number of possible permutations , modulo .
Note: In the first test case, there are distinct permutation that can be made using the process: , , , .
In the second test case, there is only one distinct permutation that can be made using the process: .
In the third test case, there are distinct permutation that can be made using the process: , .
In the fourth test case, there are distinct permutation that can be made using the process: , .
In the fifth test case, there is only one distinct permutation that can be made using the process: .