Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

SPRIMPER - Short Prime Permutations

Given two positive integers n and m, we call m a prime permutation of n, if m is prime and can be obtained by zero or more permutations of the digits of n. Permutations with leading zeros are invalid.

Input

Input starts with a positive integer t<100 in a single line, then t lines follow.
Each of the t lines contains one positive integer n<106.

Output

For every n print the number of distinct prime permutations of n in a single line.

Example

Input:
2
13
110

Output:
2
1

Hint: If you (also) like optimizing for speed, you may try the classical version.


Added by:numerix
Date:2011-03-28
Time limit:12.35s
Source limit:10000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: SCM qobi
Resource:own problem

hide comments
2013-12-20 21:36:25 Piotr KÄ…kol
Done.
2013-12-19 23:23:01 Hallvard Norheim Bø
@Piotr: Python 2.7 solutions need rejudge.

Last edit: 2013-12-19 23:23:29
2011-09-23 19:03:57 Hallvard Norheim Bø
Why is #5713653 reported to use 0k of memory when in reality it uses 12MB?

edit: looks like a SPOJ bug, all recent C submissions are listed with 0k mem usage.

update: the bug appears to be fixed now.

Last edit: 2011-09-26 05:24:24
2011-04-04 17:37:34 Piotr KÄ…kol
Done.
2011-04-04 09:17:56 numerix
Sorry, there was an error in the testcases that is fixed, now.
I did a rejudge, but it didn't effect the submissions in SHORTEN contest. Then I submitted your latest solution to check. It appeared with my name and so I tried to disqualify it, but that doesn't work either.
Piotr, please disqualify my submission.
2011-04-03 21:59:28 HWK
Could you say me which n gives WA?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.