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;
const double PI = acos((double)-1);
int ts, ts2;
long long gcd(long long x, long long y) {
  long long t;
  for (; y != 0;) {
    t = x % y;
    x = y;
    y = t;
  }
  return x;
}
int fs[100005], ss[100005], ss2, a[9][9], px[30], py[30], p2, sz, n, ans,
    tag2[9], q10[9];
int gg[6][10005];
void DFS(int k, int num, int add) {
  int i, j, t1, t, nx = px[k], ny = py[k];
  if (ny == 2 && nx != n || k > p2) {
    t = px[k - 1];
    num = num * q10[n - t] + add;
    if (fs[num]) return;
    if (k > p2) {
      ans++;
      return;
    }
    num = a[nx][1];
    add = 0;
    for (j = px[k] + 1; j <= n; j++) add = add * 10 + a[px[k]][j];
    if (nx == 2) {
      ans += gg[n][add + q10[n - 2] * a[2][1]];
      return;
    }
  }
  for (i = 9; i >= 0; i--) {
    a[nx][ny] = a[ny][nx] = i;
    if (nx == n && ny < n &&
        (i % 2 == 0 && (i != 2 || i == 2 && a[ny][1] != 0) ||
         i == 5 && a[ny][1] != 0))
      continue;
    if (nx < n && (a[nx][n] == 2 || a[nx][n] == 5) && i > 0) {
      i = 1;
      continue;
    }
    DFS(k + 1, num * 10 + i, add);
  }
}
int getw(int x) {
  int t1 = x, t2 = 0;
  for (; t1; t1 /= 10, t2++)
    ;
  return t2;
}
int main() {
  int i, j, k, t1, t2, t3, t4, t5, t, TE, p;
  double u1, u2, u3, u4, u5;
  char c1, c2, c3;
  srand((unsigned)time(0));
  scanf("%d", &TE);
  for (q10[0] = 1, i = 1; i <= 8; q10[i] = q10[i - 1] * 10, i++)
    ;
  fs[1] = 1;
  fs[0] = 1;
  for (i = 2; i <= 100000; i++) {
    if (!fs[i]) ss[++ss2] = i;
    for (j = 1; j <= ss2 && ss[j] * i <= 100000; j++) {
      fs[i * ss[j]] = 1;
      if (i % ss[j] == 0) break;
    }
  }
  for (i = 2; i <= 100000; i++)
    if (!fs[i]) {
      t1 = getw(i);
      t1 = max(t1, 2);
      for (j = t1; j <= 5; j++) {
        t2 = i % q10[j - 2] + (i / q10[j - 1] * q10[j - 2]);
        gg[j][t2]++;
      }
    }
  for (; TE; TE--) {
    scanf("%d", &p);
    if (fs[p]) {
      printf("0\n");
      continue;
    }
    for (sz = 0, t1 = p; t1; sz++, t1 /= 10)
      ;
    n = sz;
    for (t1 = p, i = sz; t1; a[i][1] = t1 % 10, t1 /= 10, i--)
      ;
    p2 = 0;
    for (i = n; i > 1; i--)
      for (j = 2; j <= i; j++) p2++, px[p2] = i, py[p2] = j;
    ans = 0;
    DFS(1, a[n][1], 0);
    printf("%d\n", ans);
  }
  return 0;
}