#P9880. GG and YY's Binary Number

GG and YY's Binary Number

GG and YY's Binary Number

Problem Description

GG and YY are honing their skills with binary numbers. They have a set VV comprising nn binary numbers: V={v1,v2,,vn}V = \{v_1, v_2, \ldots, v_n\}. Additionally, they have mm queries determined by intervals [l1,r1],[l2,r2],,[lm,rm][l_1, r_1], [l_2, r_2], \ldots, [l_m, r_m]. For each query interval [li,ri][l_i, r_i], they aim to compute the count of unique subsets UU taken from VV such that the xor sum of the elements of UU lies within [li,ri][l_i, r_i]. The results should be provided modulo 109+710^9 + 7. Specifically, for each [li,ri][l_i, r_i], compute:

$$\left( \sum_{j \in [l_i, r_i]} \sum_{\{u_1, u_2, \ldots, u_k\} \subseteq V} [u_1 \oplus u_2 \oplus \ldots \oplus u_k = j] \right) \bmod (10^9 + 7) $$

where \oplus represents the xor operation and square brackets [][\cdot] denote the Iverson bracket. Please note that the xor sum of an empty set is 00. In the Iverson bracket notation, if the condition inside the bracket is true, the value is 11; otherwise, it is 00. For instance, [u1u2uk=j][u_1 \oplus u_2 \oplus \ldots \oplus u_k = j] is 11 if the xor sum of u1,u2,,uku_1, u_2, \ldots, u_k equals jj, and 00 otherwise.

Input

The first line contains one integer tt (1t1001 \le t \le 100), indicating the number of test cases. The first line of each case contains two integers nn and mm (1n,m2501\le n,m\le 250), indicating the size of the sets VV and WW. The following line contains nn binary integers v1,,vnv_1,\ldots,v_n (0vi<22500\le v_i< 2^{250}), indicating the binary integers in VV. The following mm lines present the mm queries. The ii-th line continas two binary integers li,ril_i,r_i (0liri<22500\le l_i\le r_i<2^{250}), indicating the query interval. It is guaranteed that there will be no leading zeros in the binary numbers, with the exception of 00. For instance, the binary number 110110 corresponds to the decimal number 66.

Output

For each test case, output mm integers in mm lines, indicating the results of the queries.

Sample Input

1
4 2
100 0 1 101
1 10
10 100

Sample Output

4
4

Source

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