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 PYTHON):

Solution:
from collections import defaultdict
def primes(n):
    pr = range(n)
    for i in xrange(2,n):
        if not pr[i]: continue
        ii=i*i
        if ii>n: break
        pr[ii::i]=[0]*len(pr[ii::i])
    return filter(None,pr)[1:]
pr = primes(100000)
pe = defaultdict(lambda: defaultdict(int))
for p in pr:
    pe[p%10][p/100]+=1

ph = defaultdict(lambda: defaultdict(int))
for p in pr:
    ph[p/100][p/10%10]+=1

def pc(l):
    a = 10**(l-1)
    b = a*10
    pp = [x for x in pr if x<b]
    pd = [defaultdict(list) for _ in xrange(l)]
    pl = [defaultdict(int) for _ in xrange(l)]
    ap = [set() for _ in xrange(l)]
    for i in xrange(1,l):
        a = 10**(l-i)
        for p in pp:
            pd[i][p/a].append(p)
            ap[i].add(p/a)
        for k in pd[i].keys(): pl[i][k] = len(pd[i][k])
    return pd,ap,pl

dd = [pc(i) for i in xrange(6)]

def digits(p,n,r = None):
    if r is None: r = [0]*n
    else: r = [x*10 for x in r]
    for i in xrange(n):
        r[-i-1]+=(p%10)
        p/=10
    return r

bx = {}
def sbx(a,b,c):
    r = 0
    for k,v in ph[a].iteritems():
        r += v*pe[k][b]
    bx[c]=r
    return r

z1 = [j%10 for j in xrange(100000)]
z2 = [j/10%10 for j in xrange(100000)]
def solve5(p,(d,a,l)):
    pd = digits(p,5)
    r = 0

    for i in d[1][pd[1]]:
        pd2 = digits(i,5,pd)
        aa,bb = pd2[4]*10, pd2[3]*10
        for j in d[2][pd2[2]]:
            a = z1[j]+aa
            b = bb+z2[j]
            c = (a<<10)|b

            if c in bx: r+=bx[c]
            else: r+= sbx(a,b,c)

    return r

def solve4(p,(d,a,l)):
    pd = digits(p,4)
    r = 0
    for i in d[1][pd[1]]:
        a = i%10+pd[3]*10
        b = i/10%10+pd[2]*10
        c = (a<<10)|b
        if c in bx: r+=bx[c]
        else: r+= sbx(a,b,c)
    return r

def solve3(p,(d,a,l)):
    pd = digits(p,3)
    a,b = pd[2],pd[1]
    r = sbx(a,b,(a<<10)|b)
    return r

def solve2(p,(d,a,l)):
    return len(d[1][p%10])

t = input()
ah = {}
for _ in xrange(t):
    p = input()
    if p in ah:
        print ah[p]
        continue
    r = 0
    if p>=10000: r = solve5(p,dd[5])
    elif p>=1000: r = solve4(p,dd[4])
    elif p>=100: r = solve3(p,dd[3])
    else: r = solve2(p,dd[2])
    ah[p] = r
    print r