#P7439. [2017年杭电多校]Function

[2017年杭电多校]Function

Function

Problem Description

You are given a permutation aa from 00 to n1n - 1 and a permutation bb from 00 to m1m - 1. Define that the domain of function ff is the set of integers from 00 to n1n - 1, and the range of it is the set of integers from 00 to m1m - 1. Please calculate the quantity of different functions ff satisfying that f(i)=bf(ai)\displaystyle f(i) = b_{f(a_i)} for each ii from 00 to n1n - 1. Two functions are different if and only if there exists at least one integer from 00 to n1n - 1 mapped into different integers in these two functions. The answer may be too large, so please output it in modulo 109+710^9 + 7.

Input

The input contains multiple test cases. For each case: The first line contains two numbers n,n, mm. (1n100000,1m100000)(1 \leq n \leq 100000, 1 \leq m \leq 100000) The second line contains nn numbers, ranged from 00 to n1n - 1, the ii-th number of which represents ai1a_{i - 1}. The third line contains mm numbers, ranged from 00 to m1m - 1, the ii-th number of which represents bi1b_{i - 1}. It is guaranteed that n106,\sum{n} \leq 10^6, m106\sum{m} \leq 10^6.

Output

For each test case, output " Case #xx: yy " in one line (without quotes), where xx indicates the case number starting from 11 and yy denotes the answer of corresponding case.

Sample Input

3 2

1 0 2

0 1

3 4

2 0 1

0 2 3 1

Sample Output

Case #1: 4

Case #2: 4

Source

2017 Multi-University Training Contest - Team 1