

1. The expected number of moves can be fractional.
2. Ninja cannot go outside the array i.e if he is at (n - 1)-th position he can only move if he gets 1 as an outcome in dice.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains one integer, ‘N’, denoting the size of the board.
For each test case, return a double value. If the returned value is correct with an error margin of 0.001 to -0.001. then the output will be 1 else 0.
You do not need to input or print anything, as it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10^9
Time Limit: 1 sec.
Here, as we know that dice can give us 6 moves, so we can reach a particular step from its previous 6 steps. The expected number of dice rolls required to get '1' as an outcome is 6. similarly for getting ‘2’, ‘3’, '4', '5', ‘6’ is also 6. We can reach at position ‘n’ from ‘n - 1’ by getting ‘1’, from ‘n - 2’ by getting 2, and so on. Thus the expected dice rolls required to get at position ‘n' is 1 more than the average dice roll required to get at the previous 6 positions.
The Recurrence relation can be described as:
A[n] = 1 + ( A[n - 1] + A[n - 2] + A[n - 3] + A[n - 4] + A[n - 5] + A[n - 6] ) / 6.
This can be observed as extended Fibonacci series, we can apply Matrix Exponential technique to the above relation to find the answer.
A[n - 1] = 1+ (A[n - 2] + A[n - 3] + A[n - 4] + A[n - 5] + A[n - 6] + A[n - 7]) / 6
Substracing A[n - 1] from A[n], we get.
A[n] = 7 * (A[n - 1]) / 6 - (A[n - 7]) / 6
The matrix multiplier is as follows:
[[7 / 6, 1, 0, 0, 0, 0, 0 ],
[ 0, 0, 1, 0, 0, 0, 0 ],
[ 0, 0, 0, 1, 0, 0, 0 ],
[ 0, 0, 0, 0, 1, 0, 0 ],
[ 0, 0, 0, 0, 0, 1, 0 ],
[ 0, 0, 0, 0, 0, 0, 1 ],
[- 1 / 6, 0, 0, 0, 0, 0, 0 ]]
Returns the product of matrix ‘a’ and matrix ‘b’.