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.Comparator;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		int testCount = Integer.parseInt(in.next());
		for (int i = 1; i <= testCount; i++)
			solver.solve(i, in, out);
		out.close();
	}
}

class TaskE {

    static int[] primes = IntegerUtils.generatePrimes(100000);

    static int getRest(int n, int p, int pos) {
        StringBuilder s = new StringBuilder(String.valueOf(p));
        s.reverse();
        while (s.length() < n) {
            s.append("0");
        }
        s.reverse();
        s.deleteCharAt(pos);
        return Integer.parseInt(s.toString());
    }

    static int[] needToHave = new int[] {0, 0, 0, 1, 3, 6};
    static int[][][] options;
    static {
        options = new int[6][10000][5];
        for (int len = 2; len <= 5; ++len) {
            for (int pr : primes) {
                if (String.valueOf(pr).length() <= len) {
                    for (int pos = 1; pos < len; ++pos) {
                        int rest = getRest(len, pr, pos);
                        ++options[len][rest][pos];
                    }
                }
            }
        }
    }

    int[] pDigits;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
//        for (int i : primes) {
//            out.print(solveFor(i) + ",");
//            out.flush();
//        }
        out.println(solveFor(in.nextInt()));
    }

    long solveFor(int p) {
        String ps = String.valueOf(p);
        pDigits = new int[ps.length()];
        for (int i = 0; i < pDigits.length; ++i) {
            pDigits[i] = ps.charAt(i) - '0';
        }
        int n = ps.length();
        long res = 0;
        int[] digits = new int[needToHave[n]];
        for (int i = 0; i < needToHave[n]; ++i) {
            digits[i] = 0;
        }
        if (n == 5) {
            for (int i = 0; i < 1000; ++i) {
                int row = pDigits[1] * 1000 + i;
                if (options[n][row][1] != 0) {
                    for (int j = 0; j < 1000; ++j) {
                        int second = pDigits[2] * 1000 + (i / 100) * 100 + j / 10;
                        int third = pDigits[3] * 1000 + ((i % 100) / 10) * 100 + (j / 100) * 10 + j % 10;
                        int f = pDigits[4] * 1000 + (i % 10) * 100 + ((j % 100) / 10) * 10 + j % 10;
                        long cur = options[n][row][1] * 1L * options[n][second][2] * options[n][third][3] * options[n][f][4];
                        res += cur;
                    }
                }
            }
            return res;
        }
        while (true) {
            int[] m = fillMatrix(digits, n);
            long cur = 1;
            for (int i = 1; i < n; ++i) {
                cur *= options[n][m[i]][i];
            }
            res += cur;
            if (!next(digits)) break;
        }
        return res;
    }

    private boolean next(int[] digits) {
        if (digits.length == 0) return false;
        for (int i = digits.length - 1; i >= 0; --i) {
            if (digits[i] != 9) {
                ++digits[i];
                for (int j = i + 1; j < digits.length; ++j) {
                    digits[j] = 0;
                }
                return true;
            }
        }
        return false;
    }

    private int[] fillMatrix(int[] number, int n) {
        int[][] a = new int[n][n];
        for (int i = n-1; i >= 0; --i) {
            a[i][0] = pDigits[i];
        }
        int[] res = new int[n];
        int cnt = 0;
        for (int i = 1; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                a[i][j] = a[j][i] = number[cnt++];
            }
            res[i] = getNumber(a[i], i, n);
        }
        return res;
    }

    private int getNumber(int[] a, int pos, int n) {
        int res = 0;
        for (int i = 0; i < n; ++i) {
            if (i != pos) {
                res = res * 10 + a[i];
            }
        }
        return res;
    }
}

class IntegerUtils {
    public static int[] generatePrimes(int upLimit) {
        int[] isPrime = generateBitPrime(upLimit);
        ArrayList<Integer> result = new ArrayList<Integer>();
        for (int i = 0; i < upLimit; ++i) {
            if ((isPrime[i >> 5] >>> (i & 31) & 1) == 1) {
                result.add(i);
            }
        }
        int[] resultArray = new int[result.size()];
        for (int i = 0; i < result.size(); ++i) {
            resultArray[i] = result.get(i);
        }
        return resultArray;
    }

    private static int[] generateBitPrime(int upLimit) {
        int[] isPrime = new int[(upLimit + 31) >> 5];
        if (upLimit < 2) {
            return isPrime;
        }
        Arrays.fill(isPrime, -1);
        isPrime[0] &= -4;
        for (int i = 2; i * i < upLimit; ++i) {
            if ((isPrime[i >> 5] >>> (i & 31) & 1) == 1) {
                for (int j = i * i; j < upLimit; j += i) {
                    isPrime[j >> 5] &= (-1 - (1 << (j & 31)));
                }
            }
        }
        return isPrime;
    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

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

    public String next() {
        return nextString();
    }
}