You are given a number pad as shown in the figure below, and you also have a ‘knight’ piece from chess. Your task is to determine how many different ‘N’ digit numbers can be formed by placing the ‘knight’ anywhere on the number pad and moving the ‘knight’ according to the rules of chess.

Return the solution modulo 10^9 + 7.
For example:
You are given ‘N’ = 2, all the unique 2 digit numbers formed moving the knight on the number pad are [04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94]. Hence the answer is 20.
The first line of input contains a single integer ‘T’ representing the number of test cases.
The first and the only line of each test case contains a single integer ‘N’.
Output Format:
Print a single integer for each test case, representing the number of distinct numbers formed by moving the knight.
Print a separate line for each test case.
1 <= T <= 10
1 <= N <= 10^3
Time Limit: 1 sec
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function.
2
2
1
20
10
For the first test case, ‘N’ = 2, all the unique 2 digit numbers formed moving the knight on the number pad are [04, 06, 16, 18, 27, 29, 34, 38, 40, 43, 49, 60, 61, 67, 72, 76, 81, 83, 92, 94]. Hence the answer is 20.
For the second test case, ‘N’ = 1, all the unique 1 digit numbers formed moving the knight on the number pad are [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Hence the answer is 10.
2
1232
99
506096595
168850940
Try the brute force approach recursively.
In this approach, we will visit each position in the number pad and count the number of distinct numbers that can be dialled. We will make a map of all the places to be visited from a given number.
We create a recursive function helper(currPos, nextPositions, digitsRem), currPos is the current key on the number pad, nextPositions is the map of the next positions from any key, and digitsRem is the number of digits left to form the number.
Algorithm:
O(2^N), Where N is the given integer.
For each call, we are recursively calling the function again on an average of 2 times . Hence the time complexity is O(2^N).
O(N), Where N is the given integer.
The recursion stack will take O(N) space.