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>
int z[5] = {0}, ww = 0, lx[100000] = {0};
int my[5][10000] = {0}, to[5][10000] = {0};
int our[1000][1000] = {0};
int tt(int h) {
  if (h == ww) {
    return 1;
  }
  int xx = 0, yy = 0, i = 0, bb = 1, now = 0, ans = 0;
  for (i = 0; i < ww - h; i++) {
    bb *= 10;
  }
  bb /= 10;
  if (ww == 5 && h == 3) {
    now = 0;
    for (i = 0; i < h; i++) {
      now = now * 10 + z[i] / 10 % 10;
    }
    xx = now;
    now = 0;
    for (i = 0; i < h; i++) {
      now = now * 10 + z[i] % 10;
    }
    yy = now;
    if (our[xx][yy] != -1) {
      return our[xx][yy];
    }
  }
  now = 0;
  for (i = 0; i < h; i++) {
    now = now * 10 + z[i] / bb % 10;
  }
  if (h == ww - 1) {
    if (my[ww - h][now] != -1) {
      ans += to[ww - h][now] - my[ww - h][now] + 1;
    }
    return ans;
  }
  for (i = my[ww - h][now]; i != -1 && i <= to[ww - h][now]; i++) {
    z[h] = lx[i];
    ans += tt(h + 1);
  }
  if (ww == 5 && h == 3) {
    our[xx][yy] = ans;
  }
  return ans;
}
bool u[100000] = {0};
int main() {
  int t = 0, e = 0, p = 0, g = 0, i = 0, j = 0, x = 0, w = 0, r = 0;
  g = 0;
  for (i = 2; i < 100000; i++) {
    if (!u[i]) {
      lx[g++] = i;
      if (i < 400) {
        for (j = i * i; j < 100000; j += i) {
          u[j] = true;
        }
      }
    }
  }
  memset(my, 0XFF, sizeof(my));
  memset(to, 0XFF, sizeof(to));
  for (i = 0; i < g; i++) {
    r = 10;
    for (j = 1; j <= 4; j++) {
      if (my[j][lx[i] / r] == -1) {
        my[j][lx[i] / r] = i;
      }
      to[j][lx[i] / r] = i;
      r *= 10;
    }
  }
  memset(our, 0XFF, sizeof(our));
  while (scanf("%d", &t) == 1) {
    while (t--) {
      scanf("%d", &p);
      x = p;
      ww = 0;
      while (x) {
        ww++;
        x /= 10;
      }
      z[0] = p;
      printf("%d\n", tt(1));
    }
  }
  return 0;
}