In the far, far distant future, a war unleashes between humans and the AI, which results in the total destruction of the universe. In the end of all the catastrophe, you find yourself in a rather small world, a 3×3 grid, and life has become quite boring.
In an attempt to humor yourself, you start solving unique math questions, and here's one you have been trying to solve:
Inputs:
First line of input will contain the number of test cases N.
Each of next N lines will contain S,T and K for that case.
Outputs:
Output N lines containing the probability for each testcase as described before.
Constraints:
1≤N≤100
1≤S,T≤9
1≤K≤1018
Problem Setter: Kevin Mathew T
In the first testcase there is no way of of going from 1 to 1 in 1 move.
In the second testcase, You are initially standing at 1, three possible ways to be at cell 1 after 2 moves.
1−2−1
1−4−1
1−5−1
Hence the probability becomes 13∗15+13∗15+13∗18=740
And (7∗40−1)%(109+7)=975000007