Under construction

Still being built. Things may change

Innocence

Time limit1sMemory limit512 MB

Summary
Count arrays of length N with every element in [L, R] whose XOR equals K, modulo 1e9+7, for several K values per test case.
Level

Hard8 of 10

Topics
Bit manipulation, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

David is a young child. He likes playing combinatorial games, for example, the Nim game. He is just an amateur but he is sophisticated with game theory. This time he has prepared a problem for you.

Given integers NN, LL, RR and KK, count the number of arrays of length NN whose elements all lie between LL and RR (inclusive) and whose bitwise exclusive-OR equals KK. Print the count modulo 109+710^9 + 7.

David also wants you to answer several values of KK to make sure your solution is completely correct.

Input

The first line contains one integer TT, the number of test cases.

Each test case is described as follows. The first line contains four space-separated integers NN, LL, RR and QQ, meaning there are QQ queries with the same NN, LL, RR but different KK. The second line contains QQ space-separated integers KK.

1≤T≤10001 \le T \le 1000, 1≤N≤1091 \le N \le 10^9, 0≤L≤R<2300 \le L \le R < 2^{30}, 1≤Q≤1001 \le Q \le 100, 0≤K<2300 \le K < 2^{30}.

No more than 100 test cases fail to satisfy 1≤N≤151 \le N \le 15 and 0≤L,R,K<2150 \le L, R, K < 2^{15}.

Output

For each query, print the answer modulo 109+710^9 + 7 on its own line.

Hint

In the first sample, there are two ways to select one number 3 and one number 4 such that the exclusive-OR of them is 7.

In the second sample, there are three ways to select one number 3 and two numbers 4 and one way to select three numbers 3 such that the exclusive-OR of them is 3.

Examples1

  1. Example 1

    Input
    3
    2 3 4 2
    0 7
    3 3 4 2
    3 4
    5 5 7 4
    5 6 7 8
    
    Expected output
    2
    2
    4
    4
    61
    61
    61
    0