Problem: Polycarpus has t safes. The password for each safe is a square matrix consisting of decimal digits '0' ... '9' (the sizes of passwords to the safes may vary). Alas, Polycarpus has forgotten all passwords, so now he has to restore them.

Polycarpus enjoys prime numbers, so when he chose the matrix passwords, he wrote a prime number in each row of each matrix. To his surprise, he found that all the matrices turned out to be symmetrical (that is, they remain the same after transposition). Now, years later, Polycarp was irritated to find out that he remembers only the prime numbers pi, written in the first lines of the password matrices.

For each safe find the number of matrices which can be passwords to it.

The number of digits in pi determines the number of rows and columns of the i-th matrix. One prime number can occur in several rows of the password matrix or in several matrices. The prime numbers that are written not in the first row of the matrix may have leading zeros.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 30) — the number of safes. Next t lines contain integers pi (10 ≤ pi ≤ 99999), pi is a prime number written in the first row of the password matrix for the i-th safe. All pi's are written without leading zeros.

Output

Print t numbers, the i-th of them should be the number of matrices that can be a password to the i-th safe. Print the numbers on separate lines.

Examples

Input

4
11
239
401
9001


Output

4
28
61
2834

Note

Here is a possible password matrix for the second safe: 
    
    
      
    239  
    307  
    977  
    

Here is a possible password matrix for the fourth safe: 
    
    
      
    9001  
    0002  
    0002  
    1223   
    

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.awt.Point;
import static java.lang.Math.*;

public class P161E {
    static List<String> P = new ArrayList<String>();
    static Set<Integer> S = new HashSet<Integer>();
    static int[][][][] second = new int[10][10][10][10];
    static int[][][][] third = new int[10][10][10][10];
    static int[][][][] fourth = new int[10][10][10][10];
    static int[][][][] fifth = new int[10][10][10][10];

    public static boolean prime(int n) {
        int lim = (int)Math.sqrt(n);
        for(int i=2; i<=lim; i++)
            if(n%i==0) return false;
        return true;
    }
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        long L = 100000;
        for(int p=2; p<L; p++) {
            int d1 = (p/10000)%10;
            int d2 = (p/1000)%10;
            int d3 = (p/100)%10;
            int d4 = (p/10)%10;
            int d5 = p%10;
            if(prime(p)) {
                second[d1][d3][d4][d5]++;
                third[d1][d2][d4][d5]++;
                fourth[d1][d2][d3][d5]++;
                fifth[d1][d2][d3][d4]++;
                P.add(p+"");
                S.add(p);
            }
        }

        int T = in.nextInt();
        for(int i=0; i<T; i++) {
            long ans = 0;
            int p = in.nextInt();
            int d1 = (p/10000)%10;
            int d2 = (p/1000)%10;
            int d3 = (p/100)%10;
            int d4 = (p/10)%10;
            int d5 = p%10;
            if(p >= 10000) {
                for(int a23 = 0; a23<10; a23++)
                for(int a24 = 0; a24<10; a24++)
                for(int a25 = 0; a25<10; a25++)
                for(int a34 = 0; a34<10; a34++)
                for(int a35 = 0; a35<10; a35++)
                for(int a45 = 0; a45<10; a45++) {
                    ans += second[d2][a23][a24][a25] * third[d3][a23][a34][a35] * fourth[d4][a24][a34][a45] * fifth[d5][a25][a35][a45];
                }
                System.out.println(ans);
            }
            else if(p >= 1000) {
                for(int a23 = 0; a23<10; a23++)
                for(int a24 = 0; a24<10; a24++)
                for(int a25 = 0; a25<10; a25++)
                for(int a34 = 0; a34<10; a34++)
                for(int a35 = 0; a35<10; a35++)
                for(int a45 = 0; a45<10; a45++) {
                    int r2 = d3*1000 + a23*100 + a24*10 + a25;
                    int r3 = d4*1000 + a24*100 + a34*10 + a35;
                    int r4 = d5*1000 + a25*100 + a35*10 + a45;
                    if(S.contains(r2) && S.contains(r3) && S.contains(r4))
                        ans++;
                }
                System.out.println(ans);
            }
            else {
                List<String> X = new ArrayList<String>();
                String s = p+"";
                X.add(s);
                System.out.println(ways(1,s.length(), X));
            }
        }
    }

    public static char c(String s, int i, int len) {
        int diff = len - s.length();
        if(i < diff) return '0';
        return s.charAt(i-diff);
    }
    public static long ways(int row, int len, List<String> so_far) {
        if(row == len) return 1;
        long ans = 0;
        char[] ch = new char[row];
        for(int i=0; i<row; i++)
            ch[i] = c(so_far.get(i), row, len);
        String start = new String(ch);

        for(String s:P) {
            if(s.length() > len) continue;
            while(s.length() < len) s = "0"+s;
            if(!s.startsWith(start)) continue;
            so_far.add(s);
            ans += ways(row+1, len, so_far);
            so_far.remove(s);
        }
        return ans;
    }
}