#P7854. Kidnapper's Matching Problem

Kidnapper's Matching Problem

Kidnapper's Matching Problem

Problem Description

It is preferrable to read the pdf statment. One day when you were sitting in the couch and eating chips, a guy called you, who claimed that his name was Cuber QQ and he had your girlfriend kidnapped. This seems quite unlikely to you because you do not even have a girlfriend. However, to kill the boring time of Sunday afternoon, you asked how much the ransom is. Surprisingly, Cuber QQ is not interested in your money, the ransom is the answer to a matching problem. It turns out that Cuber QQ is a lover of binary operators, xor especially. First of all, he shall give you a pair of sequences aa and bb, with length nn and mm respectively. Given that aa and bb do not necessarily have the same length, they do not exactly make a pair . Therefore consecutive subsequences of aa are used to make pairs with bb, That makes nm+1n-m+1 pairs: al,al+1,,al+m1a_l, a_{l + 1}, \ldots, a_{l + m - 1} and bb for all 1lnm+11 \le l \le n-m+1. For each pair (al,al+1,,al+m1;b)(a_l, a_{l + 1}, \ldots, a_{l + m - 1}; b), we say they are xor-matched if their pairwise-xor 's are all available in a pre-defined set SS. Concretely, the pair is a match if and only if al+i1bi2Sa_{l+i-1} \oplus b_i \in 2_{\oplus}^{S} of all 1im1 \le i \le m. 2S2_{\oplus}^{S} is defined as the set of all possible xor-sum of SS's subsets, i.e.,

$$2_{\oplus}^{S} = \{ t | t = \bigoplus_{w \in X} w, X \subseteq S \} $$

Note that, since {}\{\} is always a valid subset of SS, 00 is always included in 2S2_{\oplus}^{S}. Now Cuber QQ wants you to tell him, for which ll's, al,al+1,,al+m1a_l, a_{l + 1}, \cdots, a_{l + m - 1} makes a match with bb. He is not sending your illusory girlfriend back before you correctly answer his question.

Input

The first line contains an integer TT (1T21041 \le T \le 2 \cdot 10^4), denotes the number of test cases. Each test case begins with three space-separated integers nn (1n21051 \le n \le 2 \cdot 10^5), mm (1mmin(n,51041 \le m \le \min(n, 5 \cdot 10^4)) and kk (1k1001 \le k \le 100), denoting the lengths of aa, bb and the size of SS. The next line contains nn space-separated integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai<2300 \le a_i < 2^{30}). The next line contains mm space-separated integers b1,b2,,bmb_1, b_2, \cdots, b_m (0bi<2300 \le b_i < 2^{30}). The last line contains kk space-separated integers S1,S2,,SkS_1, S_2, \cdots, S_k (0Si<2300 \le S_i < 2^{30}). It is guaranteed that $\sum n \le 1.2 \cdot 10^6, \sum m \le 3 \cdot 10^5, \sum k \le 6 \cdot 10^5$.

Output

For each case, you should output:

$$\sum_{i = 1}^{n - m + 1} [(a_i, a_{i + 1}, \cdots, a_{i + m - 1}) \text{ matches } b] \cdot 2^{i - 1} \bmod (10^9 + 7) $$

where [condition][\text{condition}] equals 1 if condition\text{condition} holds and 00 otherwise.

Sample Input

2
4 2 2
2 5 7 6
3 4
5 6
13 3 3
1 1 4 5 1 4 1 9 1 9 8 1 0
2 5 1
1 2 15

Sample Output

2
80

Source

2020 Multi-University Training Contest 8