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.io.*;
import java.util.*;

public class E implements Runnable {
    private MyScanner in;
    private PrintWriter out;

    private int n;
    private boolean[] prime;
    private int[] pow;

    private long count(int[][] m, int row, int col) {
        if (row == n) {
            return 1;
        }
        if (col == n) {
            int str = 0;
            for (int i = 0; i < n; ++i) {
                if (i < row) {
                    str += pow[n - 1 - i] * m[i][row];
                } else if (i > row) {
                    str += pow[n - 1 - i] * m[row][i];
                }
            }
            int num = 0;
            for (int i = 0; i < 10; ++i) {
                if (prime[str + pow[n - 1 - row] * i]) {
                    ++num;
                }
            }
            if (num == 0) {
                return 0;
            }
            return count(m, row + 1, row + 2) * num;
        }
        long ans = 0;
        for (int i = 0; i < 10; ++i) {
            m[row][col] = i;
            ans += count(m, row, col + 1);
        }
        return ans;
    }

    private long find(String s) {
        int p = Integer.parseInt(s);
        n = s.length();
        int[][] m = new int[n][n];
        for (int i = n - 1; i >= 0; --i) {
            m[0][i] = p % 10;
            p /= 10;
        }
        return count(m, 1, 2);
    }

    private void sieve(boolean[] prime) {
        int p = prime.length;
        Arrays.fill(prime, true);
        prime[0] = prime[1] = false;
        for (int i = 2; i * i < p; ++i) {
            if (prime[i]) {
                for (int j = i * i; j < p; j += i) {
                    prime[j] = false;
                }
            }
        }
    }

    private void solve() {
        prime = new boolean[100000];
        sieve(prime);
        pow = new int[6];
        pow[0] = 1;
        for (int i = 1; i < 6; ++i) {
            pow[i] = pow[i - 1] * 10;
        }
        int t = in.nextInt();
        for (int i = 0; i < t; ++i) {
            String s = in.next();
            out.println(find(s));
        }
    }

    @Override
    public void run() {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    public static void main(String[] args) {
        new E().run();
    }

    static class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            try {
                st = null;
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public boolean hasNext() {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            try {
                while (br.ready()) {
                    st = new StringTokenizer(br.readLine());
                    if (st != null && st.hasMoreTokens()) {
                        return true;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return false;
        }
    }
}