You are given a tree consisting of nodes. The () node of the tree has been assigned a binary value , that is . You are also given queries.
In each query, you are given 2 nodes and . Initialize an empty string. Now, consider the simple path between these 2 nodes(from to ) 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 corresponds to LSB.
Since the output can be very large, you need to calculate the decimal representation modulo
You are given 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) space separated integers where the integer denotes the decimal representation of the binary string obtained on the simple path between the two vertices in the query. Don't forget to take modulo
Constraints
In the first test case, we have . The tree is shown below:
We now answer the queries:
In the second test case, we have . The tree is shown below:
We now answer the queries: