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.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Locale;
import java.io.OutputStream;
import java.util.RandomAccess;
import java.io.PrintWriter;
import java.util.AbstractList;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.math.BigDecimal;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(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 {
    private boolean[] isPrime = NumberUtils.generateIsPrime(99999);
    private char[][] data;
    private int n;
    private int answer;
    private int[] absent1;
    private int[] absent2;
    private int[] absent3;
    private int[] absent4;

    public TaskE() {
        absent1 = new int[10000];
        absent2 = new int[10000];
        absent3 = new int[10000];
        absent4 = new int[10000];
        for (int i = 1; i < 100000; i++) {
            if (isPrime[i]) {
                absent1[i % 1000 + (i / 10000) * 1000]++;
                absent2[i % 100 + (i / 1000) * 100]++;
                absent3[i % 10 + (i / 100) * 10]++;
                absent4[i / 10]++;
            }
        }
    }

    private void dfs(int x, int y) {
        if (x == n && y == 0) {
            work();
            return;
        }
        int nx = x, ny = y + 1;
        if (ny == n) {
            ny = 0;
            nx++;
        }
        if (x <= y || y == 0) {
            dfs(nx, ny);
            return;
        }
        for (char c = '0'; c <= '9'; c++) {
            data[x][y] = data[y][x] = c;
            dfs(nx, ny);
        }
    }

    private void work() {
        int result = 1;
        for (int i = 1; i < n; i++) {
            int currentCount = 0;
            for (char c = '0'; c <= '9'; c++) {
                data[i][i] = c;
                if (isPrime[Integer.parseInt(String.valueOf(data[i]))]) {
                    currentCount++;
                }
            }
            result *= currentCount;
        }
        answer += result;
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        String num = in.next();
        n = num.length();
        data = new char[n][n];
        for (int i = 0; i < n; i++) {
            data[i][0] = data[0][i] = num.charAt(i);
        }
        answer = 0;
        if (n <= 4) {
            dfs(1, 1);
        } else {
            int[][] data = new int[5][5];
            for (int i = 0; i < 5; i++) {
                data[0][i] = data[i][0] = num.charAt(i) - '0';
            }
            for (int t1 = 0; t1 < 10; t1++) {
                data[1][2] = data[2][1] = t1;
                for (int t2 = 0; t2 < 10; t2++) {
                    data[1][3] = data[3][1] = t2;
                    for (int t3 = 0; t3 < 10; t3++) {
                        data[1][4] = data[4][1] = t3;
                        for (int t4 = 0; t4 < 10; t4++) {
                            data[2][3] = data[3][2] = t4;
                            for (int t5 = 0; t5 < 10; t5++) {
                                data[2][4] = data[4][2] = t5;
                                for (int t6 = 0; t6 < 10; t6++) {
                                    data[3][4] = data[4][3] = t6;
                                    answer += absent1[data[1][0] * 1000 + data[1][2] * 100 + data[1][3] * 10 + data[1][4]] *
                                            absent2[data[2][0] * 1000 + data[2][1] * 100 + data[2][3] * 10 + data[2][4]] *
                                            absent3[data[3][0] * 1000 + data[3][1] * 100 + data[3][2] * 10 + data[3][4]] *
                                            absent4[data[4][0] * 1000 + data[4][1] * 100 + data[4][2] * 10 + data[4][3]];
                                }
                            }
                        }
                    }
                }
            }
        }
        out.println(answer);
    }
}

class NumberUtils {

    public static boolean[] generateIsPrime(int N) {
        if (N < 0) throw new IllegalArgumentException();
        if (N == 1) return new boolean[]{false, false};
        boolean[] isPrime = new boolean[N + 1];
        Arrays.fill(isPrime, true);
        isPrime[0] = isPrime[1] = false;
        for (int i = 2; i * i <= N; i++) {
            if (isPrime[i]) {
                for (int j = i * i; j <= N; j += i) {
                    isPrime[j] = false;
                }
            }
        }
        return isPrime;
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 20];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public String next() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }

class OutputWriter {
    private PrintWriter writer;

    public OutputWriter(OutputStream stream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void println(int x) {
        writer.println(x);
    }

    public void close() {
        writer.close();
    }

    }