XOR operation

2.7

9 votes
Medium, Probablity, Addition Rules, Expectation, Mathematics
Problem

You are provided a number . In one step, a number  is randomly selected from the interval  and  is replaced by  where  is the Bitwise XOR operation. Determine the expected value of  after  steps modulo .

There are multiple test cases in a single input file.
You can represent the answer as a rational fraction with . To provide the answer, you should print .

Input format

  • First line: An integer  denoting the number of test cases 
  • Each test case consists of three integers , and  in a single line

Output format

For each test case, print the answer in a new line.

Constraints

Sample Input
2
3 1 0
4 2 1
Sample Output
500000005
320000005
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

-

Editor Image

?