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

Solution:
#include <bits/stdc++.h>
using namespace std;
bool prime[2 * 100500];
int pr[100500], prs;
int nxt[100500];
int ten[10];
int a[7][7];
vector<int> pd[100500];
int onedig[100500];
int solve(int n) {
  if (n == 1) return onedig[a[n][0]];
  int *b = a[n];
  int *aa = a[n - 1];
  int lim = nxt[(b[0] + 1) * ten[n]];
  int ans = 0;
  for (int pri = nxt[b[0] * ten[n]]; pri < lim; pri++) {
    vector<int> &v = pd[pr[pri]];
    for (int i = 0; i < (n - 1); i++) {
      aa[n - 2 - i] = b[n - 1 - i] * 10 + v[i];
    }
    ans += solve(n - 1);
  }
  return ans;
}
void solve1(int p0) {
  vector<int> d;
  while (p0 >= 10) d.push_back(p0 % 10), p0 /= 10;
  reverse(d.begin(), d.end());
  int n = ((int)((d).size()));
  for (int i = 0; i < (n); i++) a[n][i] = d[i];
  printf("%d\n", solve(n));
}
int main() {
  memset(prime, 1, sizeof prime);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= 2 * 100500; i++)
    if (prime[i])
      for (int j = i * i; j < 2 * 100500; j += i) prime[j] = false;
  prs = 0;
  for (int i = 0; i < (100500); i++)
    if (prime[i]) pr[prs++] = i;
  nxt[0] = nxt[1] = 0;
  for (int i = 1; i < prs; i++) {
    for (int j = pr[i - 1] + 1; j <= pr[i]; j++) nxt[j] = i;
  }
  ten[0] = 1;
  for (int i = 0; i < (7); i++) ten[i + 1] = ten[i] * 10;
  for (int i = 0; i < (100500); i++)
    if (prime[i]) {
      int p = i;
      for (int _ = 0; _ < (8); _++) pd[i].push_back(p % 10), p /= 10;
    }
  for (int i = 0; i < (100500 / 10); i++) {
    for (int d = 0; d < (10); d++) onedig[i] += prime[i * 10 + d];
  }
  int __;
  scanf("%d", &__);
  for (int _ = 0; _ < (__); _++) {
    int p;
    scanf("%d", &p);
    solve1(p);
  }
  return 0;
}