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

public class Main
{	
	public BufferedReader in;
	public PrintStream out;
	
	public boolean log_enabled = true;
	
	static int[] primes;
	static int p_count;
	static boolean[] is_prime;

	public static void get_primes(int n)
	{
		boolean[] v =  is_prime = new boolean[n+1];
		int i,j;
		
		v[0] = v[1] = false;
		
		for (i=2; i<=n;i++)
		{
			v[i] = true;
		}
		
		for (i=2; i*i<=n;i++)
		{
			if (v[i])
			{
				for (j=i; i*j<=n; j++)
				{
					v[i*j]=false;
				}
			}
		}
	}
	
	int set_dg(int x, int k, int d)
	{
		int i,z = 1;
		for (i=1; i<k; i++)
		{
			z *= 10;
		}
		
		return (x/(10*z)*10 + d)*z;
	}
	
	long calc(int x, int n)
	{
		int cnt = 0;
		
		int i,d=1;
		int[] p10 = new int[10];
		int[] pref = new int[10];
		int[] suf = new int[10];
		int[] numbs = new int[10];
		
		suf[1] = x+1;
		pref[1] = 0;
		
		for (i=n; i>0;i--)
		{
			p10[i] = d;
			d *= 10;
		}
		
		for (i=n; i>1;i--)
		{
			pref[i] = (x % 10) * p10[n-i+2];
			x /= 10;
		}
		
		int k = 2;		
		suf[2] = 0;
		
		while (k > 1)
		{
			if (suf[k] == p10[k])
			{
				k--;
				continue;
			}
			
			numbs[k] = 0;
			for (i=0; i<10;i++)
			{
				if (is_prime[(10*pref[k]+i)*p10[k]+suf[k]])
				{
					numbs[k] ++;
				}
			}
			
			x = suf[k]++;
			
			if (numbs[k]>0)
			{
				for (i=n; i>k; i--)
				{
					pref[i] = set_dg(pref[i], i-k, x%10);
					x /= 10;
				}
				
				if (k==n)
				{
					x = 1;
					for (i=2; i<=n;i++)
					{	
						x *= numbs[i];
					}
					
					/*
					out.println("*************");
					for (i=1; i<=n; i++)
					{
						out.println(pref[i]*p10[i]*10+suf[i]-1);
					}
					
					out.printf("  ::: %d\n", x); */
					
					
					cnt += x;
					
					k--;
				}
				else
				{
					suf[++k] = 0;
				}
			}
		}
		
		return cnt;
	}
	
	public void test()
	{
		get_primes(100000);
		
		int i,t,d,k,n=readInt();
		
		for (i=0; i<n; i++)
		{
			t = readInt();
			d = 10;
			k = 1;
			while (t>d)
			{
				d *= 10;
				k++;
			}
			
			out.println(calc(t, k));
		}
	}
    
	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;
			
			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));
			
			
		}
		catch (Exception e)
		{
			return;
		}
		
		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)					
			{
				test();
			}
		}
	}
	
	public static void main(String args[])
	{
		new Main().run();
	}
	
	private StringTokenizer tokenizer = null;
	
	public int readInt() 
	{
        return Integer.parseInt(readToken());
    }
   
    public long readLong() 
	{
        return Long.parseLong(readToken());
    }
   
    public double readDouble() 
	{
        return Double.parseDouble(readToken());
    }
   
	public String readLn()
	{	
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}
	
    public String readToken() 
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens()) 
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }
	
	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}
	
	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}
	
	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}
		
		out.printf(format, args);
	}
}