Mehta's Dilemma
13% Success276 Attempts50 Points1s Time Limit256MB Memory1024 KB Max Code

Background:
Mehta's friend Verma has challenged him in a maths puzzle. The puzzle involves playing with digits, their product and square root.

Task:
Numbers which have product of their digits as perfect square in their decimal representation are called Fancy Numbers. So, you have to report the count of Fancy Numbers having length less than or equal to given number N. Length of the number is defined as number of digits in its decimal representation.

Input:
First Line of the input contains number of test cases T.
Next T Lines contain a single number N denoting the maximum length.

Output:
Output the count of Fancy Numbers having length less than or equal to given number N in a separate line for all test cases T modulo 109 + 7.

Note:
0 is a perfect square and has length 1.
Any number of length X does not have leading zeros i.e one is represented as 1 and not 01, 001.

Constraints:
Subtask 1:
1 <= T <= 10
1 <= N <= 10000
Subtask 2:
1 <= T <= 5
1 <= N <= 1018

Examples
Input
4
1
2
3
4
Output
4
30
312
3560
Explanation

Case 1: Fancy numbers of length less than equal to 1 are:- [0,1,4,9] as their product itself is [0,1,4,9]. Hence, there are only 4 Fancy numbers of length less than equal to 1.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading Editor...
Results