D. Divided Xor
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Given a permutation $$$p$$$ of length $$$n$$$, consider the undirected simple graph $$$G$$$ with $$$n$$$ vertices constructed as follows.

  • Vertices $$$i$$$ and $$$j$$$ ($$$i \lt j$$$) are connected if and only if for all $$$k$$$ between $$$i$$$ and $$$j$$$ it holds that $$$p_k \lt \min(p_i, p_j)$$$.

Given an integer $$$K$$$ and $$$n$$$ non-negative integers $$$b_1, b_2, \dots b_n$$$, compute the number of non-empty subsequences $$$s$$$ of $$$\{1, 2, \dots n\}$$$ such that

$$$$$$b_{s_1} \oplus b_{s_2} \oplus \dots b_{s_{|s|}} = K$$$$$$

and the set of nodes $$$s$$$ forms an independent set in $$$G$$$. Here, $$$\oplus$$$ represents the bitwise XOR operation.

Input

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases.

The first line of each test case contains two integers $$$n$$$ and $$$K$$$ ($$$2 \le n \le 10^3, 0 \le K \lt 2^{10}$$$).

The second and third lines of each test case contain the permutation $$$p$$$ and the sequence $$$b$$$ respectively ($$$1 \le p_i \le n, 0 \le b_i \lt 2^{10}$$$). It is guaranteed that $$$p$$$ is a permutation.

It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^3$$$.

Output

For each test case, print a single integer on a new line, the answer to the problem modulo $$$10^9 + 7$$$.

Example
Input
2
5 1
5 2 3 1 4
0 1 1 1 1
6 0
4 3 1 6 2 5
2 1 2 0 2 1
Output
5
5
Note

In the first test case, the $$$5$$$ independent sets satisfying the conditions above are $$$\{1\}$$$, $$$\{2\}$$$, $$$\{3\}$$$, $$$\{4\}$$$ and $$$\{1, 5\}$$$.