You are given a tree G consisting of N nodes. The ith(1≤i≤N) node of the tree has been assigned a binary value Ai, that is Ai=0/1. You are also given Q queries.
In each query, you are given 2 nodes u and v. Initialize an empty string. Now, consider the simple path between these 2 nodes(from u to v) and append the binary values obtained on this path to the string. Your task is to find the decimal representation of this binary string. Note that the bit at v corresponds to LSB.
Since the output can be very large, you need to calculate the decimal representation modulo 1000000007 (109+7)
You are given T test cases.
Warning: Use FAST I/O Methods.
Input format
Output format
For each test case(in a separate line), output(in a separate line) Q space separated integers where the ith integer denotes the decimal representation of the binary string obtained on the simple path between the two vertices in the ith query. Don't forget to take modulo 1000000007 (109+7)
Constraints
1≤T≤10001≤N,Q≤5×1050≤Ai≤11≤u,v≤NIt is guaranteed that given edges form a treeSum of N over all test cases does not exceed 5×105Sum of Q over all test cases does not exceed 5×105
In the first test case, we have N=6,A=[1,0,1,0,1,1],Q=3. The tree is shown below:
We now answer the queries:
In the second test case, we have N=2,A=[1,1],Q=2. The tree is shown below:
We now answer the queries: