## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022

C. Where is the Pizza?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While searching for the pizza, baby Hosssam came across two permutations $a$ and $b$ of length $n$.

Recall that a permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\left[2,3,1,5,4\right]$ is a permutation, but $\left[1,2,2\right]$ is not a permutation ($2$ appears twice in the array) and $\left[1,3,4\right]$ is also not a permutation ($n=3$ but there is $4$ 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 $n$.

Prof. Slim Codeforces Solution | Codeforces Problem Solution 2022

Dorms War Codeforces Solution | Codeforces Problem Solution 2022

Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022

Very Suspicious Codeforces Solution | Codeforces Problem Solution 2022

Hemose on the Tree Codeforces Solution | Codeforces Problem Solution 2022

Jee, You See? Codeforces Solution | Codeforces Problem Solution 2022

Specifically, he mixed up the permutations to form a new array $c$ in the following way.

• For each $i$ ($1\le i\le n$), he either made ${c}_{i}={a}_{i}$ or ${c}_{i}={b}_{i}$.
• The array $c$ is a permutation.

You know permutations $a$$b$, and values at some positions in $c$. Please count the number different permutations $c$ that are consistent with the described process and the given values. Since the answer can be large, print it modulo ${10}^{9}+7$.

It is guaranteed that there exists at least one permutation $c$ that satisfies all the requirements.

Input

The first line contains an integer $t$ ($1\le t\le {10}^{5}$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($1\le n\le {10}^{5}$) — the length of the permutations.

The next line contains $n$ distinct integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($1\le {a}_{i}\le n$) — the first permutation.

The next line contains $n$ distinct integers ${b}_{1},{b}_{2},\dots ,{b}_{n}$ ($1\le {b}_{i}\le n$) — the second permutation.

The next line contains $n$ distinct integers ${d}_{1},{d}_{2},\dots ,{d}_{n}$ (${d}_{i}$ is either $0$${a}_{i}$, or ${b}_{i}$) — the description of the known values of $c$. If ${d}_{i}=0$, then there are no requirements on the value of ${c}_{i}$. Otherwise, it is required that ${c}_{i}={d}_{i}$.

It is guaranteed that there exists at least one permutation $c$ that satisfies all the requirements.

It is guaranteed that the sum of $n$ over all test cases does not exceed $5\cdot {10}^{5}$.

Output

For each test case, print the number of possible permutations $c$, modulo ${10}^{9}+7$.