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.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
	static PrintWriter pw;
	static int limit = 100000;
	static final boolean d = false;
	static Prime[] map = new Prime[100000];
	
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		if (d) pw = new PrintWriter(new File("output.txt"));
		else   pw = new PrintWriter(System.out);
		generatePrimes();
		
		if (d) {
			pw.println(f("10001"));
		} else {
			int n = Integer.parseInt(in.readLine());
			
			for (int i = 0 ; i < n ; i++) {
				String s = in.readLine();
				
				pw.println(f(s));
			}
		}		
		pw.close();
	}
	
	static void generatePrimes() {
		map[0] = new Prime();
		for (int i = 2 ; i < 100000 ; i++) {
			boolean status = true;
			
			for (int j = 2 ; j * j <= i ; j++) {
				if (i % j == 0) {
					status = false;
					break;
				}
			}
			
			if (status) {
				add(i);
				addToZero(i);
			}
		}
	}
	static void add(int i) {
		int st = 10;
		
		for (int j = 1 ; i / st > 0 ; j++) {
			if (map[i / st] == null) {
				map[i / st] = new Prime();
			}
			
			map[i / st].add(i % st, j);
			
			st *= 10;
		}
	}
	static void addToZero(int i) {
		int size = 0;
		for (int st = 1 ; i / st > 0 ; ) {
			size++;
			st *= 10;
		}
		

		for (int j = size ; j < 5 ; j++) {
			map[0].add(i, j);
		}
	} 
	static class Prime {
		ArrayList<ArrayList<Integer>> array;
		
		Prime() {
			array = new ArrayList<ArrayList<Integer>>();
			
			for (int i = 0 ; i < 5 ; i++) {
				array.add(new ArrayList<Integer>());
			}
		}
		
		void add(int i, int w) {
			array.get(w).add(i);
		}
		
		int getElem(int n, int i) {
			return array.get(n).get(i);
		}
		
		int getSize(int n) {
			return array.get(n).size();
		}
		
		ArrayList<Integer> subArray(int n) {
			return array.get(n);
		}
	}
	
	static int f(String s) {
		int n = s.length();
		
		int[] A = new int[n - 1];
		
		for (int i = 0 ; i < n - 1 ; i++) {
			A[i] = s.charAt(i + 1) - 48;
		}
		
		return rec(1, n, A, 0);
	}
	
	static int rec(int stepi, int n, int[] A, int sum) {
		if (stepi == (n - 1)) {
			if (d) pw.println("last: " + A[stepi - 1]);
			if (map[A[stepi - 1]] != null) {
				return map[A[stepi - 1]].getSize(1);
			} else {
				return 0;
			}
		}
		
		int subSum = 0;		
		
		ArrayList<Integer> temp = map[A[stepi - 1]].subArray(n - stepi);
		
		if (d) pw.println("take =" + stepi + "; subArray =" + (n - stepi));
		
		if (temp != null) {
			for (int i = stepi - 1 ; i < (n - 1) ; i++) {
				A[i] *= 10;
			}
			if (d) printArray(A);
			for (int i = 0 ; i < temp.size() ; i++) {
				if (d) pw.println("step =" + stepi + ";temp =" + temp.get(i));
				
				int st;
				
				st = 10;
				for (int j = stepi ; j < (n - 1) ; j++) {
					A[n - 2 - j + stepi] /= 10;
					A[n - 2 - j + stepi] *= 10;
					A[n - 2 - j + stepi] += (temp.get(i) / (st / 10)) % 10;
					st *= 10;								
				}
				
				if (d) printArray(A);
				
				subSum += rec(stepi + 1, n, A, sum);
			}for (int i = stepi - 1 ; i < (n - 1) ; i++) {
				A[i] /= 10;
			}
		}
		
		return subSum;
	}
	
	static void printArray(int[] A) {
		for (int i = 0 ; i < A.length ; i++) {
			pw.print(A[i] + " ");
		}
		pw.println("DEL");
	}
}