#P9877. Chords

Chords

Chords

Problem Description

Imagine a mystical forest where a magic piano with nn keys resides. Each key of this piano represents a note, denoted by positive integers from 11 through nn. In musical terms, a chord is defined as a set of notes played together in harmony. The type or class of a chord is categorized based on the difference between its root note (the lowest note) and the other notes in the chord. For instance, the chord class known as minor triad includes all chords of the format {x,x+3,x+7x, x+3, x+7}. Similarly, the chord class dominant seventh includes all chords that follow the pattern {x,x+4,x+7,x+10x, x+4, x+7, x+10}. For each key xx on the piano (which produces the note xx), you can play it with axa_x different strengths, each of which produces a unique sound. As a result, you can produce axa_x distinct sounds from that note. More interestingly, for a minor triad with root note xx as an example, you can produce ax×ax+3×ax+7a_x \times a_{x+3} \times a_{x+7} unique sounds. Now, consider a given chord class represented by {x+b1,x+b2,...,x+bmx + b_1, x+b_2, ..., x+{b_m}}. Your task is to calculate the total number of different sounds you can produce when you are free to choose any root note xx.

Input

The first line of the input contains a single integer TT (1T1031 \leq T \leq 10^3), denoting the number of test cases. The first line of each test case contains two integers n,mn,m (1mn5×1051 \leq m \leq n \leq 5\times 10^5) separated by space, denoting the number of keys in the piano and the number of notes in the given chord class. The second line of each test case contains nn positive integers a1,,ana_1, \ldots, a_n (0<ax<10621255690 < a_x < 1062125569), each representing the number of different strengths that can be applied to the corresponding key xx. The third line of each test case contains mm ascending integers b1,,bmb_1, \ldots, b_m (0=b1<b2<<bm<n0 = b_1 < b_2 < \ldots < b_m < n), denoting the given chord class. It is guaranteed that the sum of nn over all test cases will not exceed 10610 ^ 6.

Output

For each test case, output the answer modulo 10621255691062125569 in a single line.

Sample Input

1
5 2
3 4 2 5 1
0 2

Sample Output

28

Source

2023“钉耙编程”中国大学生算法设计超级联赛(8)