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 int maxp = 100000;
vector<int> e[6][6][maxp];
bool isPrime[maxp];
int prime[maxp];
int cnt, n, len, tot;
int ans[6][6];
int a[6], row[6];
void DFS(int i, int j) {
  if (i == len - 1) {
    tot += e[len][i][row[i]].size();
    return;
  }
  int sz = e[len][i][row[i]].size();
  for (int k = 0; k < sz; ++k) {
    int x = e[len][i][row[i]][k];
    bool flag = 1;
    for (int z = len - 1; z >= j; --z) {
      ans[i][z] = ans[z][i] = x % 10;
      x /= 10;
      if (e[len][i + 1][row[z] * 10 + ans[z][i]].size() == 0) {
        flag = 0;
        break;
      }
    }
    if (!flag) continue;
    for (int z = i + 1; z < len; ++z) row[z] = row[z] * 10 + ans[z][i];
    DFS(i + 1, j + 1);
    for (int z = i + 1; z < len; ++z) row[z] = row[z] / 10;
  }
}
int main() {
  cnt = 0;
  memset(isPrime, 1, sizeof(isPrime));
  for (int i = 2; i < maxp; ++i)
    if (isPrime[i]) {
      prime[cnt++] = i;
      for (int j = i + i; j < maxp; j += i) isPrime[j] = 0;
    }
  for (int ll = 2; ll < 6; ++ll)
    for (int i = 0; i < cnt; ++i) {
      memset(a, 0, sizeof(a));
      int l = 0, x = prime[i];
      while (x) {
        a[l++] = x % 10;
        x /= 10;
      }
      if (l > ll) break;
      int tmp = 0;
      for (int j = ll - 1; j >= 0; --j) {
        tmp = tmp * 10 + a[j];
        int p = 0;
        for (int k = j - 1; k >= 0; --k) p = p * 10 + a[k];
        e[ll][ll - j][tmp].push_back(p);
      }
    }
  int T;
  for (scanf("%d", &T); T > 0; --T) {
    scanf("%d", &n);
    memset(ans, 0, sizeof(ans));
    len = 0;
    for (int x = n; x; x /= 10) a[len++] = x % 10;
    reverse(a, a + len);
    for (int i = 0; i < len; ++i) ans[0][i] = ans[i][0] = row[i] = a[i];
    tot = 0;
    DFS(1, 1);
    printf("%d\n", tot);
  }
  return 0;
}